Copyright | © 2018-2020 IOHK |
---|---|
License | Apache-2.0 |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Provides a strict implementation of a non-empty map.
This implementation is based on the implementation of
Strict
provided by the
containers
package, but provides an extra guarantee
that the map contains at least one entry at all times.
Synopsis
- data NonEmptyMap k v
- fromList :: Ord k => NonEmpty (k, v) -> NonEmptyMap k v
- fromMap :: Map k v -> Maybe ( NonEmptyMap k v)
- singleton :: Ord k => k -> v -> NonEmptyMap k v
- toList :: NonEmptyMap k v -> NonEmpty (k, v)
- toMap :: Ord k => NonEmptyMap k v -> Map k v
- insert :: Ord k => k -> v -> NonEmptyMap k v -> NonEmptyMap k v
- delete :: Ord k => k -> NonEmptyMap k a -> Maybe ( NonEmptyMap k a)
- lookup :: Ord k => k -> NonEmptyMap k v -> Maybe v
- unionWith :: Ord k => (v -> v -> v) -> NonEmptyMap k v -> NonEmptyMap k v -> NonEmptyMap k v
Map type
data NonEmptyMap k v Source #
A non-empty map from keys of type
k
to values of type
v
.
Instances
Construction
fromList :: Ord k => NonEmpty (k, v) -> NonEmptyMap k v Source #
Builds a non-empty map from a list of key-value pairs.
If the list contains more than one value for the same key, the last value for the key is retained.
fromMap :: Map k v -> Maybe ( NonEmptyMap k v) Source #
Builds a non-empty map from the given map.
If the given map is empty, this function returns
Nothing
.
singleton :: Ord k => k -> v -> NonEmptyMap k v Source #
Creates a map with a single element.
Deconstruction
toList :: NonEmptyMap k v -> NonEmpty (k, v) Source #
Converts a non-empty map to a list of key-value pairs.
Insertion
insert :: Ord k => k -> v -> NonEmptyMap k v -> NonEmptyMap k v Source #
Inserts a new key and value in the map.
If the key is already present in the map, the associated value is replaced with the supplied value.
Deletion
delete :: Ord k => k -> NonEmptyMap k a -> Maybe ( NonEmptyMap k a) Source #
Deletes a key and its value from the map.
When the key is not a member of the map, the original map is returned.
This function returns
Nothing
if the delete operation reduces the number
of elements to zero.
Lookup
lookup :: Ord k => k -> NonEmptyMap k v -> Maybe v Source #
Looks up the value of a key in the map.
This function will return the corresponding value as '(Just value)',
or
Nothing
if the key isn't in the map.
Combination
unionWith :: Ord k => (v -> v -> v) -> NonEmptyMap k v -> NonEmptyMap k v -> NonEmptyMap k v Source #
Finds the union of two maps, with the given combining function.