Module

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

#empty Source

empty :: forall v k. HashMap k v

#singleton Source

singleton :: forall v k. Hashable k => k -> v -> HashMap k v

#lookup Source

lookup :: forall v k. Hashable k => k -> HashMap k v -> Maybe v

#insert Source

insert :: forall v k. Hashable k => k -> v -> HashMap k v -> HashMap k v

#delete Source

delete :: forall v k. Hashable k => k -> HashMap k v -> HashMap k v

#isEmpty Source

isEmpty :: forall v k. HashMap k v -> Boolean

#member Source

member :: forall v k. Hashable k => k -> HashMap k v -> Boolean

#size Source

size :: forall v k. HashMap k v -> Int

#update Source

update :: forall v k. Hashable k => (v -> Maybe v) -> k -> HashMap k v -> HashMap k v

Update or delete the value for a key in a map

#alter Source

alter :: forall v k. Hashable k => (Maybe v -> Maybe v) -> k -> HashMap k v -> HashMap k v

Insert the value, delete a value, or update a value for a key in a map

#union Source

union :: forall v k. Hashable k => HashMap k v -> HashMap k v -> HashMap k v

Union two maps, same as Semigroup.append aka (<>)

For duplicate keys, we keep the value from the left map.

#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 Tuples 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 Tuples. No particular ordering is guaranteed.

Modules
Data.HashMap