Data.Containers

mono-traversable-0.10.2: Type classes for mapping, folding, and traversing monomorphic containers

Safe Haskell | None
Language | Haskell2010

Data.Containers

Description

Warning: This module should be considered highly experimental.

Synopsis

- class (Monoid set, Semigroup set, MonoFoldable set, Eq (ContainerKey set), GrowingAppend set) => SetContainer set where
  - type ContainerKey set
  - member :: ContainerKey set -> set -> Bool
  - notMember :: ContainerKey set -> set -> Bool
  - union :: set -> set -> set
  - difference :: set -> set -> set
  - intersection :: set -> set -> set
  - keys :: set -> [ContainerKey set]
- class PolyMap map where
  - differenceMap :: map value1 -> map value2 -> map value1
  - intersectionMap :: map value1 -> map value2 -> map value1
  - intersectionWithMap :: (value1 -> value2 -> value3) -> map value1 -> map value2 -> map value3
- class BiPolyMap map where
  - type BPMKeyConstraint map key :: Constraint
  - mapKeysWith :: (BPMKeyConstraint map k1, BPMKeyConstraint map k2) => (v -> v -> v) -> (k1 -> k2) -> map k1 v -> map k2 v
- class (MonoTraversable map, SetContainer map) => IsMap map where
  - type MapValue map
  - lookup :: ContainerKey map -> map -> Maybe (MapValue map)
  - insertMap :: ContainerKey map -> MapValue map -> map -> map
  - deleteMap :: ContainerKey map -> map -> map
  - singletonMap :: ContainerKey map -> MapValue map -> map
  - mapFromList :: [(ContainerKey map, MapValue map)] -> map
  - mapToList :: map -> [(ContainerKey map, MapValue map)]
  - findWithDefault :: MapValue map -> ContainerKey map -> map -> MapValue map
  - insertWith :: (MapValue map -> MapValue map -> MapValue map) -> ContainerKey map -> MapValue map -> map -> map
  - insertWithKey :: (ContainerKey map -> MapValue map -> MapValue map -> MapValue map) -> ContainerKey map -> MapValue map -> map -> map
  - insertLookupWithKey :: (ContainerKey map -> MapValue map -> MapValue map -> MapValue map) -> ContainerKey map -> MapValue map -> map -> (Maybe (MapValue map), map)
  - adjustMap :: (MapValue map -> MapValue map) -> ContainerKey map -> map -> map
  - adjustWithKey :: (ContainerKey map -> MapValue map -> MapValue map) -> ContainerKey map -> map -> map
  - updateMap :: (MapValue map -> Maybe (MapValue map)) -> ContainerKey map -> map -> map
  - updateWithKey :: (ContainerKey map -> MapValue map -> Maybe (MapValue map)) -> ContainerKey map -> map -> map
  - updateLookupWithKey :: (ContainerKey map -> MapValue map -> Maybe (MapValue map)) -> ContainerKey map -> map -> (Maybe (MapValue map), map)
  - alterMap :: (Maybe (MapValue map) -> Maybe (MapValue map)) -> ContainerKey map -> map -> map
  - unionWith :: (MapValue map -> MapValue map -> MapValue map) -> map -> map -> map
  - unionWithKey :: (ContainerKey map -> MapValue map -> MapValue map -> MapValue map) -> map -> map -> map
  - unionsWith :: (MapValue map -> MapValue map -> MapValue map) -> [map] -> map
  - mapWithKey :: (ContainerKey map -> MapValue map -> MapValue map) -> map -> map
  - omapKeysWith :: (MapValue map -> MapValue map -> MapValue map) -> (ContainerKey map -> ContainerKey map) -> map -> map
- class (SetContainer set, Element set ~ ContainerKey set) => IsSet set where
  - insertSet :: Element set -> set -> set
  - deleteSet :: Element set -> set -> set
  - singletonSet :: Element set -> set
  - setFromList :: [Element set] -> set
  - setToList :: set -> [Element set]
- class MonoFunctor mono => MonoZip mono where
  - ozipWith :: (Element mono -> Element mono -> Element mono) -> mono -> mono -> mono
  - ozip :: mono -> mono -> [(Element mono, Element mono)]
  - ounzip :: [(Element mono, Element mono)] -> (mono, mono)
- class SetContainer set => HasKeysSet set where
  - type KeySet set
  - keysSet :: set -> KeySet set

# Documentation

class (Monoid set, Semigroup set, MonoFoldable set, Eq (ContainerKey set), GrowingAppend set) => SetContainer set where

A container whose values are stored in Key-Value pairs.

Associated Types

type ContainerKey set

The type of the key

Methods

member :: ContainerKey set -> set -> Bool

Check if there is a value with the supplied key in the container.

notMember :: ContainerKey set -> set -> Bool

Check if there isn't a value with the supplied key in the container.

union :: set -> set -> set

Get the union of two containers.

difference :: set -> set -> set

Get the difference of two containers.

intersection :: set -> set -> set

Get the intersection of two containers.

keys :: set -> [ContainerKey set]

Get a list of all of the keys in the container.

Instances

SetContainer IntSet |
Eq key => SetContainer [(key, value)] |
SetContainer (IntMap value) | This instance uses the functions from Data.IntMap.Strict.
Ord element => SetContainer (Set element) |
(Eq element, Hashable element) => SetContainer (HashSet element) |
Ord k => SetContainer (Map k v) | This instance uses the functions from Data.Map.Strict.
(Eq key, Hashable key) => SetContainer (HashMap key value) | This instance uses the functions from Data.HashMap.Strict.

class PolyMap map where

A guaranteed-polymorphic `Map`, which allows for more polymorphic versions of functions.

Methods

differenceMap :: map value1 -> map value2 -> map value1

Get the difference between two maps, using the left map's values.

intersectionMap :: map value1 -> map value2 -> map value1

Get the intersection of two maps, using the left map's values.

intersectionWithMap :: (value1 -> value2 -> value3) -> map value1 -> map value2 -> map value3

Get the intersection of two maps with a supplied function that takes in the left map's value and the right map's value.

Instances

PolyMap IntMap | This instance uses the functions from Data.IntMap.Strict.
Ord key => PolyMap (Map key) | This instance uses the functions from Data.Map.Strict.
(Eq key, Hashable key) => PolyMap (HashMap key) | This instance uses the functions from Data.HashMap.Strict.

class BiPolyMap map where

A `Map` type polymorphic in both its key and value.

Associated Types

type BPMKeyConstraint map key :: Constraint

Methods

mapKeysWith

Arguments

:: (BPMKeyConstraint map k1, BPMKeyConstraint map k2) |
=> (v -> v -> v) | combine values that now overlap
-> (k1 -> k2) |
-> map k1 v |
-> map k2 v |

Instances

BiPolyMap Map |
BiPolyMap HashMap |

class (MonoTraversable map, SetContainer map) => IsMap map where

Polymorphic typeclass for interacting with different map types

Minimal complete definition

lookup, insertMap, deleteMap, singletonMap, mapFromList, mapToList

Associated Types

type MapValue map

In some cases, `MapValue` and `Element` will be different, e.g., the `IsMap` instance of associated lists.

Methods

lookup :: ContainerKey map -> map -> Maybe (MapValue map)

Look up a value in a map with a specified key.

insertMap :: ContainerKey map -> MapValue map -> map -> map

Insert a key-value pair into a map.

deleteMap :: ContainerKey map -> map -> map

Delete a key-value pair of a map using a specified key.

singletonMap :: ContainerKey map -> MapValue map -> map

Create a map from a single key-value pair.

mapFromList :: [(ContainerKey map, MapValue map)] -> map

Convert a list of key-value pairs to a map

mapToList :: map -> [(ContainerKey map, MapValue map)]

Convert a map to a list of key-value pairs.

findWithDefault :: MapValue map -> ContainerKey map -> map -> MapValue map

Like `lookup`, but uses a default value when the key does not exist in the map.

insertWith

Arguments

:: (MapValue map -> MapValue map -> MapValue map) | function that accepts the new value and the previous value and returns the value that will be set in the map.
-> ContainerKey map | key
-> MapValue map | new value to insert
-> map | input map
-> map | resulting map

Insert a key-value pair into a map.

Inserts the value directly if the key does not exist in the map. Otherwise, apply a supplied function that accepts the new value and the previous value and insert that result into the map.

insertWithKey

Arguments

:: (ContainerKey map -> MapValue map -> MapValue map -> MapValue map) | function that accepts the key, the new value, and the previous value and returns the value that will be set in the map.
-> ContainerKey map | key
-> MapValue map | new value to insert
-> map | input map
-> map | resulting map

Insert a key-value pair into a map.

Inserts the value directly if the key does not exist in the map. Otherwise, apply a supplied function that accepts the key, the new value, and the previous value and insert that result into the map.

insertLookupWithKey

Arguments

:: (ContainerKey map -> MapValue map -> MapValue map -> MapValue map) | function that accepts the key, the new value, and the previous value and returns the value that will be set in the map.
-> ContainerKey map | key
-> MapValue map | new value to insert
-> map | input map
-> (Maybe (MapValue map), map) | previous value and the resulting map

Insert a key-value pair into a map, return the previous key's value if it existed.

Inserts the value directly if the key does not exist in the map. Otherwise, apply a supplied function that accepts the key, the new value, and the previous value and insert that result into the map.

adjustMap

Arguments

:: (MapValue map -> MapValue map) | function to apply to the previous value
-> ContainerKey map | key
-> map | input map
-> map | resulting map

Apply a function to the value of a given key.

Returns the input map when the key-value pair does not exist.

adjustWithKey

Arguments

:: (ContainerKey map -> MapValue map -> MapValue map) | function that accepts the key and the previous value and returns the new value
-> ContainerKey map | key
-> map | input map
-> map | resulting map

Equivalent to `adjustMap`, but the function accepts the key, as well as the previous value.

updateMap

Arguments

:: (MapValue map -> Maybe (MapValue map)) | function that accepts the previous value and returns the new value or `Nothing`
-> ContainerKey map | key
-> map | input map
-> map | resulting map

Apply a function to the value of a given key.

If the function returns `Nothing`, this deletes the key-value pair.

Returns the input map when the key-value pair does not exist.

updateWithKey

Arguments

:: (ContainerKey map -> MapValue map -> Maybe (MapValue map)) | function that accepts the key and the previous value and returns the new value or `Nothing`
-> ContainerKey map | key
-> map | input map
-> map | resulting map

Equivalent to `updateMap`, but the function accepts the key, as well as the previous value.

updateLookupWithKey

Arguments

:: (ContainerKey map -> MapValue map -> Maybe (MapValue map)) | function that accepts the key and the previous value and returns the new value or `Nothing`
-> ContainerKey map | key
-> map | input map
-> (Maybe (MapValue map), map) | previous/new value and the resulting map

Apply a function to the value of a given key.

If the map does not contain the key this returns `Nothing` and the input map.

If the map does contain the key but the function returns `Nothing`, this returns the previous value and the map with the key-value pair removed.

If the map contains the key and the function returns a value, this returns the new value and the map with the key-value pair with the new value.

alterMap

Arguments

:: (Maybe (MapValue map) -> Maybe (MapValue map)) | function that accepts the previous value and returns the new value or `Nothing`
-> ContainerKey map | key
-> map | input map
-> map | resulting map

Update/Delete the value of a given key.

Applies a function to previous value of a given key, if it results in `Nothing` delete the key-value pair from the map, otherwise replace the previous value with the new value.

unionWith

Arguments

:: (MapValue map -> MapValue map -> MapValue map) | function that accepts the first map's value and the second map's value and returns the new value that will be used
-> map | first map
-> map | second map
-> map | resulting map

Combine two maps.

When a key exists in both maps, apply a function to both of the values and use the result of that as the value of the key in the resulting map.

unionWithKey

Arguments

:: (ContainerKey map -> MapValue map -> MapValue map -> MapValue map) | function that accepts the key, the first map's value and the second map's value and returns the new value that will be used
-> map | first map
-> map | second map
-> map | resulting map

unionsWith

Arguments

:: (MapValue map -> MapValue map -> MapValue map) | function that accepts the first map's value and the second map's value and returns the new value that will be used
-> [map] | input list of maps
-> map | resulting map

Combine a list of maps.

When a key exists in two different maps, apply a function to both of the values and use the result of that as the value of the key in the resulting map.

mapWithKey

Arguments

:: (ContainerKey map -> MapValue map -> MapValue map) | function that accepts the key and the previous value and returns the new value
-> map | input map
-> map | resulting map

Apply a function over every key-value pair of a map.

omapKeysWith

Arguments

:: (MapValue map -> MapValue map -> MapValue map) | function that accepts the first map's value and the second map's value and returns the new value that will be used
-> (ContainerKey map -> ContainerKey map) | function that accepts the previous key and returns the new key
-> map | input map
-> map | resulting map

Apply a function over every key of a pair and run `unionsWith` over the results.

Instances

Eq key => IsMap [(key, value)] |
IsMap (IntMap value) | This instance uses the functions from Data.IntMap.Strict.
Ord key => IsMap (Map key value) | This instance uses the functions from Data.Map.Strict.
(Eq key, Hashable key) => IsMap (HashMap key value) | This instance uses the functions from Data.HashMap.Strict.

class (SetContainer set, Element set ~ ContainerKey set) => IsSet set where

Polymorphic typeclass for interacting with different set types

Methods

insertSet :: Element set -> set -> set

Insert a value into a set.

deleteSet :: Element set -> set -> set

Delete a value from a set.

singletonSet :: Element set -> set

Create a set from a single element.

setFromList :: [Element set] -> set

Convert a list to a set.

setToList :: set -> [Element set]

Convert a set to a list.

Instances

IsSet IntSet |
Ord element => IsSet (Set element) |
(Eq element, Hashable element) => IsSet (HashSet element) |

class MonoFunctor mono => MonoZip mono where

Zip operations on `MonoFunctor`s.

Methods

ozipWith :: (Element mono -> Element mono -> Element mono) -> mono -> mono -> mono

Combine each element of two `MonoZip`s using a supplied function.

ozip :: mono -> mono -> [(Element mono, Element mono)]

Take two `MonoZip`s and return a list of the pairs of their elements.

ounzip :: [(Element mono, Element mono)] -> (mono, mono)

Take a list of pairs of elements and return a `MonoZip` of the first components and a `MonoZip` of the second components.

Instances

MonoZip ByteString |
MonoZip ByteString |
MonoZip Text |
MonoZip Text |

class SetContainer set => HasKeysSet set where

Type class for maps whose keys can be converted into sets.

Associated Types

type KeySet set

Type of the key set.

Methods

keysSet :: set -> KeySet set

Convert a map into a set of its keys.

Instances

HasKeysSet (IntMap v) |
Ord k => HasKeysSet (Map k v) |
(Hashable k, Eq k) => HasKeysSet (HashMap k v) |