Module

Data.Map

Package
purescript-mapsDEPRECATED
Repository
purescript/purescript-maps

This module defines a type of maps as balanced 2-3 trees, based on http://www.cs.princeton.edu/~dpw/courses/cos326-12/ass/2-3-trees.pdf

#Map Source

data Map k v

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

Instances

#showTree Source

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

Render a Map as a String

#empty Source

empty :: forall v k. Map k v

An empty map

#isEmpty Source

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

Test if a map is empty

#singleton Source

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

Create a map with one key/value pair

#checkValid Source

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.

#lookup Source

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

Lookup a value for the specified key

#lookupLE Source

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

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

#lookupLT Source

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

Lookup a value for the greatest key less than the specified key

#lookupGE Source

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

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

#lookupGT Source

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

Lookup a value for the least key greater than the specified key

#findMax Source

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

Returns the pair with the greatest key

#findMin Source

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

Returns the pair with the least key

#member Source

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

Test if a key is a member of a map

#insert Source

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

Insert or replace a key/value pair in a map

#delete Source

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

Delete a key and its corresponding value from a map.

#pop Source

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.

#alter Source

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

#update Source

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

#fromFoldable Source

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.

#fromFoldableWith Source

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.

#toUnfoldable Source

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

#toAscUnfoldable Source

toAscUnfoldable :: 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

#keys Source

keys :: forall v k. Map k v -> List k

Get a list of the keys contained in a map

#values Source

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

Get a list of the values contained in a map

#unionWith Source

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.

#union Source

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

#unions Source

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

Compute the union of a collection of maps

#size Source

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

Calculate the number of key/value pairs in a map

#mapWithKey Source

mapWithKey :: forall v' v k. (k -> v -> v') -> Map k v -> Map k v'

Apply a function of two arguments to each key/value pair, producing a new map