Data.HashMap
- Package
- purescript-unordered-collections
- Repository
- fehrenbach/purescript-unordered-collections
#HashMap Source
data HashMap t0 t1
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, Semigroup v) => Monoid (HashMap k v)
(Hashable k, Semigroup v) => Semigroup (HashMap k v)
Functor (HashMap k)
FunctorWithIndex k (HashMap k)
(Hashable k) => Apply (HashMap k)
(Hashable k) => Bind (HashMap k)
Foldable (HashMap k)
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 k v. Hashable k => (v -> v -> v) -> k -> v -> HashMap k v -> HashMap k v
Insert the new value if the key doesn't exist, otherwise combine the existing and new values.
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, consider
using upsert
instead.
#filterWithKey Source
filterWithKey :: forall k v. (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 k v. (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 k v w. (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 f k v. 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 a k v. 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 f a k v. 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 f k v. 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 k v. Hashable k => HashMap k v -> HashMap k v -> HashMap k v
Intersect two maps.
#intersectionWith Source
intersectionWith :: forall k a b c. 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 k v w. 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.
#SemigroupHashMap Source
newtype SemigroupHashMap k v
This newtype provides a Semigroup
instance for HashMap k v
which delegates to the Semigroup v
instance of elements. This
newtype is deprecated and will be removed in the next major
version. Use HashMap
instead.
We are currently in step 2 of the following migration process:
Add
SemigroupHashMap
with the newSemigroup
instance and remove old instance fromHashMap
.The new instance uses
unionWith append
instead ofunion
. You can recover the previous, left-biased behaviour by usingSemigroupHashMap k (First v)
in place ofHashMap k v
.Add new
Semigroup
instance toHashMap
and deprecateSemigroupHashMap
.Remove
SemigroupHashMap
.
Constructors
SemigroupHashMap (HashMap k v)
Instances
Newtype (SemigroupHashMap k v) _
(Eq k, Eq v) => Eq (SemigroupHashMap k v)
(Hashable k, Hashable v) => Hashable (SemigroupHashMap k v)
Functor (SemigroupHashMap k)
FunctorWithIndex k (SemigroupHashMap k)
(Hashable k) => Apply (SemigroupHashMap k)
(Hashable k) => Bind (SemigroupHashMap k)
Foldable (SemigroupHashMap k)
FoldableWithIndex k (SemigroupHashMap k)
Traversable (SemigroupHashMap k)
TraversableWithIndex k (SemigroupHashMap k)
(Show k, Show v) => Show (SemigroupHashMap k v)
(Hashable k, Semigroup v) => Semigroup (SemigroupHashMap k v)
(Hashable k, Semigroup v) => Monoid (SemigroupHashMap k v)
- Modules
- Data.
HashMap - Data.
HashSet - Data.
Hashable
The
Foldable
instance is best used with a commutative function/Monoid
, since hash maps do not guarantee any particular order.