Data.HashMap
- Package
- purescript-unordered-containers
- Repository
- fehrenbach/purescript-unordered-containers
#HashMap Source
data HashMap k v
An immutable HashMap k v
maps Hashable
keys of type k
to
values of type v
.
The implementation uses a hash array mapped trie with path copying on updates and path compression on deletions. In the absence of hash collisions, common operations are O(log32 n).
Instances
(Eq k, Eq v) => Eq (HashMap k v)
(Eq k) => Eq1 (HashMap k)
(Hashable k) => Monoid (HashMap k v)
(Hashable k) => Semigroup (HashMap k v)
Functor (HashMap k)
FunctorWithIndex k (HashMap k)
Foldable (HashMap k)
FoldableWithIndex k (HashMap k)
Traversable (HashMap k)
TraversableWithIndex k (HashMap k)
(Show k, Show v) => Show (HashMap k v)
#keys Source
keys :: forall v k f. Unfoldable f => HashMap k v -> f k
Returns the keys of the map in no particular order.
#values Source
values :: forall v k f. Unfoldable f => HashMap k v -> f v
Returns the values of the map in no particular order.
#fromFoldable Source
fromFoldable :: forall v k f. Foldable f => Hashable k => f (Tuple k v) -> HashMap k v
Convert a Foldable
of key-value Tuple
s to a map.
For duplicate keys, later (by foldl
) values overwrite earlier values.
#fromFoldableBy Source
fromFoldableBy :: forall v k a f. Foldable f => Hashable k => (a -> k) -> (a -> v) -> f a -> HashMap k v
Convert a Foldable
to a map by extracting keys and values.
For duplicate keys, later (by foldl
) values overwrite earlier values.
fromFoldable ≡ fromFoldableBy fst snd
fromFoldableBy kf vf fa ≡ foldMap (\a -> singleton (kf a) (vf a)) fa
fromFoldableBy kf vf fa ≡ fromFoldable (map (a -> Tuple (kf a) (vf a)) fa)
#toUnfoldableBy Source
toUnfoldableBy :: forall v k a f. Unfoldable f => (k -> v -> a) -> HashMap k v -> f a
Convert a HashMap to an unfoldable functor, like Array
or List
This takes a function from key and value to the element type of
the result. For example, fixing the functor to Array
, passing
Tuple
will result in an array of key-value pairs.
toUnfoldableBy Tuple m == toUnfoldableUnordered m
toUnfoldableBy const m == keys m
toUnfoldableBy (flip const) m == values m
#toUnfoldableUnordered Source
toUnfoldableUnordered :: forall v k f. Unfoldable f => HashMap k v -> f (Tuple k v)
Convert a map to an Unfoldable
of Tuple
s.
No particular ordering is guaranteed.
- Modules
- Data.
HashMap