Map

GitHub   Edit on GitHub

A Map holds key-value pairs. Any value may be used as a key or value. Operations on a Map mutate the internal state, so it never needs to be re-assigned.

1
import Map from "map"

Values

Map.make

1
make : () -> Map<k, v>

Creates a new, empty map.

Map.makeSized

1
makeSized : Number -> Map<k, v>

Creates a new, empty map with an initial storage size for the given number of elements.

Map.get

1
get : (k, Map<k, v>) -> Option<v>

Retrieves the value associated with the given key from the map. Returns an optional result, with Some(value) if it exists and None if not.

Map.set

1
set : (k, v, Map<k, v>) -> Void

Adds a new key-value pair to the map. If the key already exists, replaces the value.

Map.update

1
update : (k, (Option<v> -> Option<v>), Map<k, v>) -> Void

Calls the updater function with the optional value at the key, with Some(value) if it exists or None if not. The updater function must return Some(newValue) if a new value should be set or None if the value should be removed from the map.

Map.contains

1
contains : (k, Map<k, v>) -> Bool

Returns true if the map contains the given key.

Map.remove

1
remove : (k, Map<k, v>) -> Void

Removes the key-value pair associated with the given key from the map.

Map.size

1
size : Map<k, v> -> Number

Returns the number of keys bound to a value within the map.

Map.isEmpty

1
isEmpty : Map<k, v> -> Number

Returns true if the map contains no key-value pairs.

Map.clear

1
clear : Map<k, v> -> Void

Removes all key-value pairs from the map.

Map.forEach

1
forEach : ((k, v) -> Void, Map<k, v>) -> Void

Iterates the given function over each key-value pair in the map.

Map.reduce

1
reduce : ((a, k, v) -> a, a, Map<k, v>) -> a

Reduces all key-value pairs within a map to a single value. The reducer function is called with the accumulator, the current key, and the current value.

Map.keys

1
keys : Map<k, v> -> List<k>

Returns a list of all keys bound to a value in the map.

Map.values

1
values : Map<k, v> -> List<v>

Returns a list of all values bound to a key in the map.

Map.toList

1
toList : Map<k, v> -> List<(k, v)>

Returns a list of all key-value pairs in the map.

Map.fromList

1
fromList : List<(k, v)> -> Map<k, v>

Creates a map from a list of key-value pairs.

Map.toArray

1
toArray : Map<k, v> -> Array<(k, v)>

Returns a array of all key-value pairs in the map.

Map.fromArray

1
fromArray : Array<(k, v)> -> Map<k, v>

Creates a map from an array of key-value pairs.

Map.filter

1
filter : ((k, v) -> Bool, Map<k, v>) -> Void

Keeps all key-value pairs that the predicate returned true for from the map.

Map.reject

1
reject : ((k, v) -> Bool, Map<k, v>) -> Void

Removes all key-value pairs that the predicate returned true for from the map.

This is a notification!