Data.HashMap
- Package
- purescript-unordered-collections
- Repository
- fehrenbach/purescript-unordered-collections
#HashMap Source
data HashMap :: Type -> Type -> Type
Immutable hash maps from keys k
to values v
.
Note that this is an unordered collection.
Instances
(Eq k, Eq v) => Eq (HashMap k v)
(Hashable k, Hashable v) => Hashable (HashMap k v)
(Hashable k) => Monoid (HashMap k v)
(Hashable k) => Semigroup (HashMap k v)
Functor (HashMap k)
FunctorWithIndex k (HashMap k)
Foldable (HashMap k)
The
Foldable
instance is best used with a commutative function/Monoid
, since hash maps do not guarantee any particular order.FoldableWithIndex k (HashMap k)
The
FoldableWithIndex
instance is best used with a commutative function/Monoid
, since hash maps do not guarantee any particular order.Traversable (HashMap k)
TraversableWithIndex k (HashMap k)
(Show k, Show v) => Show (HashMap k v)
#insertWith Source
insertWith :: forall v k. Hashable k => (v -> v -> v) -> k -> v -> HashMap k v -> HashMap k v
Insert or update a value with the given function.
The combining function is called with the existing value as the first argument and the new value as the second argument.
insertWith (<>) 5 "b" (singleton 5 "a") == singleton 5 "ab"
#fromFoldable Source
fromFoldable :: forall v k f. Foldable f => Hashable k => f (Tuple k v) -> HashMap k v
Turn a foldable functor of pairs into a hash map.
In the presence of duplicate keys, later (by foldl
) mappings
overwrite earlier mappings.
#fromFoldableBy Source
fromFoldableBy :: forall v k a f. Foldable f => Hashable k => (a -> k) -> (a -> v) -> f a -> HashMap k v
#intersection Source
intersection :: forall v k. Hashable k => HashMap k v -> HashMap k v -> HashMap k v
Intersect two maps.
For duplicate keys, we keep the value from the right map.
This is the same as Semigroup.append
aka (<>)
.
#intersectionWith Source
intersectionWith :: forall v k. Hashable k => (v -> v -> v) -> HashMap k v -> HashMap k v -> HashMap k v
Intersect two maps, combining the values for keys that appear in both maps using the given function.
intersectionWith (-) (singleton 0 3) (singleton 0 2) == singleton 0 1
#difference Source
difference :: forall v k. Hashable k => HashMap k v -> HashMap k v -> HashMap k v
Compute the difference of two maps, that is a new map of all the mappings in the left map that do not have a corresponding key in the right map.
- Modules
- Data.
HashMap - Data.
HashSet - Data.
Hashable
This is "the shallow" semigroup instance, where maps themselves are combined using
union
rather than elements being combined. For duplicate keys, values from the left map are preserved.