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"
If your update function does not use the existing value,
especially if you find yourself writing insertWith (const f)
,
consider using upsert
instead.
#filterWithKey Source
filterWithKey :: forall v k. (k -> v -> Boolean) -> HashMap k v -> HashMap k v
Remove key-value-pairs from a map for which the predicate does not hold.
Like filter
, but the predicate takes both key and value.
#filterKeys Source
filterKeys :: forall v k. (k -> Boolean) -> HashMap k v -> HashMap k v
Remove all keys from the map for which the predicate does not hold.
difference m1 m2 == filterKeys (\k -> member k m2) m1
#mapMaybeWithKey Source
mapMaybeWithKey :: forall w v k. (k -> v -> Maybe w) -> HashMap k v -> HashMap k w
Apply a function to all key value pairs in a hash map, discard
the Nothing
results, and keep the value of the Just
results.
#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.
If your input is an array, consider using fromArray
instead.
#fromArrayBy Source
fromArrayBy :: forall v k a. Hashable k => (a -> k) -> (a -> v) -> Array a -> HashMap k v
Turn an array into a hash map given extraction functions for keys and values.
This uses a mutable hash map internally and is faster than
fromFoldable
and fromFoldableBy
.
#fromFoldableBy Source
fromFoldableBy :: forall v k a f. Foldable f => Hashable k => (a -> k) -> (a -> v) -> f a -> HashMap k v
Turn a foldable functor into a hash map given extraction functions for keys and values.
If your input is an array, consider using fromArrayBy
instead.
fromFoldableBy fst snd == fromFoldable
#fromFoldableWithIndex Source
fromFoldableWithIndex :: forall v k f. FoldableWithIndex k f => Hashable k => f v -> HashMap k v
Turn a foldable functor with index into a hash map.
This can be used to convert, for example, an ordered map into a hash map with the same keys and values, or an array into a hash map with values indexed by their position in the array.
fromFoldableWithIndex ["a", "b"] == fromArray [Tuple 0 "a", Tuple 1 "b"]
#intersection Source
intersection :: forall v k. Hashable k => HashMap k v -> HashMap k v -> HashMap k v
Intersect two maps.
#intersectionWith Source
intersectionWith :: forall c b a k. Hashable k => (a -> b -> c) -> HashMap k a -> HashMap k b -> HashMap k c
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 w v k. Hashable k => HashMap k v -> HashMap k w -> 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.