Safe Haskell | None |
---|---|
Language | Haskell2010 |
Non-empty hash maps.
Synopsis
- newtype NEHashMap k v = NEHashMap {
- unNEHashMap :: HashMap k v
- singleton :: Hashable k => k -> v -> NEHashMap k v
- fromHashMap :: HashMap k v -> Maybe (NEHashMap k v)
- fromList :: (Eq k, Hashable k) => [(k, v)] -> Maybe (NEHashMap k v)
- fromNonEmpty :: (Eq k, Hashable k) => NonEmpty (k, v) -> NEHashMap k v
- toHashMap :: NEHashMap k v -> HashMap k v
- toNonEmpty :: NEHashMap k v -> NonEmpty (k, v)
- toList :: NEHashMap k v -> [(k, v)]
- lookup :: (Eq k, Hashable k) => k -> NEHashMap k v -> Maybe v
- (!?) :: (Eq k, Hashable k) => NEHashMap k v -> k -> Maybe v
- keys :: NEHashMap k v -> [k]
- union :: (Eq k, Hashable k) => NEHashMap k v -> NEHashMap k v -> NEHashMap k v
- unionWith :: (Eq k, Hashable k) => (v -> v -> v) -> NEHashMap k v -> NEHashMap k v -> NEHashMap k v
- mapKeys :: (Eq k2, Hashable k2) => (k1 -> k2) -> NEHashMap k1 v -> NEHashMap k2 v
- isInverseOf :: (Eq k, Hashable k, Eq v, Hashable v) => NEHashMap k v -> NEHashMap v k -> Bool
Documentation
newtype NEHashMap k v Source #
A non-empty hashmap is a wrapper around a normal hashmap, that
only provides a restricted set of functionalities. It doesn't
provide a Monoid
instance, nor an empty
function.
NEHashMap | |
|
Instances
Functor (NEHashMap k) Source # | |
Foldable (NEHashMap k) Source # | |
Defined in Data.HashMap.Strict.NonEmpty fold :: Monoid m => NEHashMap k m -> m # foldMap :: Monoid m => (a -> m) -> NEHashMap k a -> m # foldMap' :: Monoid m => (a -> m) -> NEHashMap k a -> m # foldr :: (a -> b -> b) -> b -> NEHashMap k a -> b # foldr' :: (a -> b -> b) -> b -> NEHashMap k a -> b # foldl :: (b -> a -> b) -> b -> NEHashMap k a -> b # foldl' :: (b -> a -> b) -> b -> NEHashMap k a -> b # foldr1 :: (a -> a -> a) -> NEHashMap k a -> a # foldl1 :: (a -> a -> a) -> NEHashMap k a -> a # toList :: NEHashMap k a -> [a] # null :: NEHashMap k a -> Bool # length :: NEHashMap k a -> Int # elem :: Eq a => a -> NEHashMap k a -> Bool # maximum :: Ord a => NEHashMap k a -> a # minimum :: Ord a => NEHashMap k a -> a # | |
Traversable (NEHashMap k) Source # | |
Defined in Data.HashMap.Strict.NonEmpty | |
(Eq k, Eq v) => Eq (NEHashMap k v) Source # | |
(Ord k, Ord v) => Ord (NEHashMap k v) Source # | |
Defined in Data.HashMap.Strict.NonEmpty compare :: NEHashMap k v -> NEHashMap k v -> Ordering # (<) :: NEHashMap k v -> NEHashMap k v -> Bool # (<=) :: NEHashMap k v -> NEHashMap k v -> Bool # (>) :: NEHashMap k v -> NEHashMap k v -> Bool # (>=) :: NEHashMap k v -> NEHashMap k v -> Bool # | |
(Show k, Show v) => Show (NEHashMap k v) Source # | |
(Eq k, Hashable k) => Semigroup (NEHashMap k v) Source # | |
(NFData k, NFData v) => NFData (NEHashMap k v) Source # | |
Defined in Data.HashMap.Strict.NonEmpty | |
(Hashable k, Hashable v) => Hashable (NEHashMap k v) Source # | |
Defined in Data.HashMap.Strict.NonEmpty | |
(FromJSON v, FromJSONKey k, Eq k, Hashable k) => FromJSON (NEHashMap k v) Source # | |
Defined in Data.HashMap.Strict.NonEmpty parseJSON :: Value -> Parser (NEHashMap k v) parseJSONList :: Value -> Parser [NEHashMap k v] | |
(ToJSON v, ToJSONKey k) => ToJSON (NEHashMap k v) Source # | |
Defined in Data.HashMap.Strict.NonEmpty toJSON :: NEHashMap k v -> Value toEncoding :: NEHashMap k v -> Encoding toJSONList :: [NEHashMap k v] -> Value toEncodingList :: [NEHashMap k v] -> Encoding | |
(Cacheable k, Cacheable v) => Cacheable (NEHashMap k v) Source # | |
singleton :: Hashable k => k -> v -> NEHashMap k v Source #
Construct a non-empty map with a single element.
fromHashMap :: HashMap k v -> Maybe (NEHashMap k v) Source #
Construct a non-empty map with the supplied mappings.
Returns Nothing
if the provided HashMap
is empty.
fromList :: (Eq k, Hashable k) => [(k, v)] -> Maybe (NEHashMap k v) Source #
Construct a non-empty map with the supplied mappings as follows:
- if the provided list contains duplicate mappings, the later mappings take precedence;
- if the provided list is empty, returns
Nothing
.
toNonEmpty :: NEHashMap k v -> NonEmpty (k, v) Source #
Convert a non-empty map to a non-empty list of key/value pairs. The closed
operations of NEHashMap
guarantee that this operation won't fail.
lookup :: (Eq k, Hashable k) => k -> NEHashMap k v -> Maybe v Source #
Return the value to which the specified key is mapped, or Nothing
if
this map contains no mapping for the key.
union :: (Eq k, Hashable k) => NEHashMap k v -> NEHashMap k v -> NEHashMap k v Source #
The union of two maps.
If a key occurs in both maps, the left map m1
(first argument) will be
preferred.
unionWith :: (Eq k, Hashable k) => (v -> v -> v) -> NEHashMap k v -> NEHashMap k v -> NEHashMap k v Source #
The union of two maps using a given value-wise union function.
If a key occurs in both maps, the provided function (first argument) will be used to compute the result.
mapKeys :: (Eq k2, Hashable k2) => (k1 -> k2) -> NEHashMap k1 v -> NEHashMap k2 v Source #
is the map obtained by applying mapKeys
f sf
to each key of s
.
The size of the result may be smaller if f maps two or more distinct keys to the same new key. In this case there is no guarantee which of the associated values is chosen for the conflicting key.
isInverseOf :: (Eq k, Hashable k, Eq v, Hashable v) => NEHashMap k v -> NEHashMap v k -> Bool Source #
Determines whether the left-hand-side and the right-hand-side are inverses of each other.
More specifically, for two maps A
and B
, isInverseOf
is satisfied when both of the
following are true:
1. ∀ key ∈ A. A[key] ∈ B ∧ B[A[key]] == key
2. ∀ key ∈ B. B[key] ∈ A ∧ A[B[key]] == key