Module

# Data.Map

Package
purescript-ordered-collections
Repository
purescript/purescript-ordered-collections

### #keysSource

``keys :: forall v k. Map k v -> Set k``

## Re-exports from Data.Map.Internal

### #MapSource

``data Map k v``

`Map k v` represents maps from keys of type `k` to values of type `v`.

#### Instances

• `(Eq k) => Eq1 (Map k)`
• `(Eq k, Eq v) => Eq (Map k v)`
• `(Ord k) => Ord1 (Map k)`
• `(Ord k, Ord v) => Ord (Map k v)`
• `(Show k, Show v) => Show (Map k v)`
• `(Ord k) => Semigroup (Map k v)`
• `(Ord k) => Monoid (Map k v)`
• `Functor (Map k)`
• `FunctorWithIndex k (Map k)`
• `Foldable (Map k)`
• `FoldableWithIndex k (Map k)`
• `Traversable (Map k)`
• `TraversableWithIndex k (Map k)`

### #valuesSource

``values :: forall v k. Map k v -> List v``

Get a list of the values contained in a map

``update :: forall v k. Ord k => (v -> Maybe v) -> k -> Map k v -> Map k v``

Update or delete the value for a key in a map

### #unionsSource

``unions :: forall f v k. Ord k => Foldable f => f (Map k v) -> Map k v``

Compute the union of a collection of maps

### #unionWithSource

``unionWith :: forall v k. Ord k => (v -> v -> v) -> Map k v -> Map k v -> Map k v``

Compute the union of two maps, using the specified function to combine values for duplicate keys.

### #unionSource

``union :: forall v k. Ord k => Map k v -> Map k v -> Map k v``

Compute the union of two maps, preferring values from the first map in the case of duplicate keys

### #toUnfoldableUnorderedSource

``toUnfoldableUnordered :: forall v k f. Unfoldable f => Map k v -> f (Tuple k v)``

Convert a map to an unfoldable structure of key/value pairs

### #toUnfoldableSource

``toUnfoldable :: forall v k f. Unfoldable f => Map k v -> f (Tuple k v)``

Convert a map to an unfoldable structure of key/value pairs where the keys are in ascending order

### #submapSource

``submap :: forall v k. Ord k => Maybe k -> Maybe k -> Map k v -> Map k v``

Returns a new map containing all entries of the given map which lie between a given lower and upper bound, treating `Nothing` as no bound i.e. including the smallest (or largest) key in the map, no matter how small (or large) it is. For example:

``````submap (Just 1) (Just 2)
(fromFoldable [Tuple 0 "zero", Tuple 1 "one", Tuple 2 "two", Tuple 3 "three"])
== fromFoldable [Tuple 1 "one", Tuple 2 "two"]

submap Nothing (Just 2)
(fromFoldable [Tuple 0 "zero", Tuple 1 "one", Tuple 2 "two", Tuple 3 "three"])
== fromFoldable [Tuple 0 "zero", Tuple 1 "one", Tuple 2 "two"]
``````

The function is entirely specified by the following property:

``````Given any m :: Map k v, mmin :: Maybe k, mmax :: Maybe k, key :: k,
let m' = submap mmin mmax m in
if (maybe true (\min -> min <= key) mmin &&
maybe true (\max -> max >= key) mmax)
then lookup key m == lookup key m'
else not (member key m')
``````

### #sizeSource

``size :: forall v k. Map k v -> Int``

Calculate the number of key/value pairs in a map

### #singletonSource

``singleton :: forall v k. k -> v -> Map k v``

Create a map with one key/value pair

### #showTreeSource

``showTree :: forall v k. Show k => Show v => Map k v -> String``

Render a `Map` as a `String`

### #popSource

``pop :: forall v k. Ord k => k -> Map k v -> Maybe (Tuple v (Map k v))``

Delete a key and its corresponding value from a map, returning the value as well as the subsequent map.

### #memberSource

``member :: forall v k. Ord k => k -> Map k v -> Boolean``

Test if a key is a member of a map

### #lookupLTSource

``lookupLT :: forall v k. Ord k => k -> Map k v -> Maybe { key :: k, value :: v }``

Look up a value for the greatest key less than the specified key

### #lookupLESource

``lookupLE :: forall v k. Ord k => k -> Map k v -> Maybe { key :: k, value :: v }``

Look up a value for the specified key, or the greatest one less than it

### #lookupGTSource

``lookupGT :: forall v k. Ord k => k -> Map k v -> Maybe { key :: k, value :: v }``

Look up a value for the least key greater than the specified key

### #lookupGESource

``lookupGE :: forall v k. Ord k => k -> Map k v -> Maybe { key :: k, value :: v }``

Look up a value for the specified key, or the least one greater than it

### #lookupSource

``lookup :: forall v k. Ord k => k -> Map k v -> Maybe v``

Look up a value for the specified key

### #isSubmapSource

``isSubmap :: forall v k. Ord k => Eq v => Map k v -> Map k v -> Boolean``

Test whether one map contains all of the keys and values contained in another map

### #isEmptySource

``isEmpty :: forall v k. Map k v -> Boolean``

Test if a map is empty

### #insertSource

``insert :: forall v k. Ord k => k -> v -> Map k v -> Map k v``

Insert or replace a key/value pair in a map

### #fromFoldableWithSource

``fromFoldableWith :: forall v k f. Ord k => Foldable f => (v -> v -> v) -> f (Tuple k v) -> Map k v``

Convert any foldable collection of key/value pairs to a map. On key collision, the values are configurably combined.

### #fromFoldableSource

``fromFoldable :: forall v k f. Ord k => Foldable f => f (Tuple k v) -> Map k v``

Convert any foldable collection of key/value pairs to a map. On key collision, later values take precedence over earlier ones.

### #foldSubmapSource

``foldSubmap :: forall m v k. Ord k => Monoid m => Maybe k -> Maybe k -> (k -> v -> m) -> Map k v -> m``

Fold over the entries of a given map where the key is between a lower and an upper bound. Passing `Nothing` as either the lower or upper bound argument means that the fold has no lower or upper bound, i.e. the fold starts from (or ends with) the smallest (or largest) key in the map.

``````foldSubmap (Just 1) (Just 2) (\_ v -> [v])
(fromFoldable [Tuple 0 "zero", Tuple 1 "one", Tuple 2 "two", Tuple 3 "three"])
== ["one", "two"]

foldSubmap Nothing (Just 2) (\_ v -> [v])
(fromFoldable [Tuple 0 "zero", Tuple 1 "one", Tuple 2 "two", Tuple 3 "three"])
== ["zero", "one", "two"]
``````

### #findMinSource

``findMin :: forall v k. Map k v -> Maybe { key :: k, value :: v }``

Returns the pair with the least key

### #findMaxSource

``findMax :: forall v k. Map k v -> Maybe { key :: k, value :: v }``

Returns the pair with the greatest key

### #filterWithKeySource

``filterWithKey :: forall v k. Ord k => (k -> v -> Boolean) -> Map k v -> Map k v``

Filter out those key/value pairs of a map for which a predicate fails to hold.

### #filterKeysSource

``filterKeys :: forall k. Ord k => (k -> Boolean) -> (Map k) ~> (Map k)``

Filter out those key/value pairs of a map for which a predicate on the key fails to hold.

### #filterSource

``filter :: forall v k. Ord k => (v -> Boolean) -> Map k v -> Map k v``

Filter out those key/value pairs of a map for which a predicate on the value fails to hold.

### #emptySource

``empty :: forall v k. Map k v``

An empty map

### #deleteSource

``delete :: forall v k. Ord k => k -> Map k v -> Map k v``

Delete a key and its corresponding value from a map.

### #checkValidSource

``checkValid :: forall v k. Map k v -> Boolean``

Check whether the underlying tree satisfies the 2-3 invariant

This function is provided for internal use.

### #alterSource

``alter :: forall v k. Ord k => (Maybe v -> Maybe v) -> k -> Map k v -> Map k v``

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