Pages
Standard Library

Search
Entities

# Map

## Functions

delete
(
key
:
key
map
:
Map(key, value)
)
:
Map(key, value)

Removes the given key from the map

``````(Map.empty()
|> Map.set("a", 1)
|> Map.delete("a")) == Map.empty()
``````
deleteValue
(
value
:
value
map
:
Map(key, value)
)
:
Map(key, value)

Removes all keys from the map which match the given value.

``````(Map.empty()
|> Map.set("a", 1)
|> Map.set("b", 1)
|> Map.deleteValue(1)) == Map.empty()
``````
empty
:
Map(x, z)

Returns an empty map.

entries
(
map
:
Map(a, b)
)
:
Array(Tuple(a, b))

Returns the array of {key, value} Tuple.

``````(Map.empty()
|> Map.set("a", 1)
|> Map.set("b", 2)
|> Map.entries()) == [{"a", 1}, {"b", 2}]
``````
findKey
(
method
:
Function(value, Bool)
map
:
Map(key, value)
)
:
Maybe(key)

Returns the first key which is matched by the given function.

``````(Map.empty()
|> Map.set("a", 0)
|> Map.set("b", 1)
|> Map.findKey((value : Number) : Bool {
value == 1
})) == Maybe.just("b")
``````
fromArray
(
array
:
Array(Tuple(a, b))
)
:
Map(a, b)

Converts an array of tuples into a Map.

`````` (Map.empty()
|> Map.set("a", 1)
|> Map.set("b", 2)
) == Map.fromArray([{"a", 1}, {"b", 2}])
``````
get
(
key
:
x
map
:
Map(x, z)
)
:
Maybe(z)

Gets the value for the given key of the given map.

``````Map.empty()
|> Map.set("key", "value")
|> Map.get("key") == Maybe.just("value")
``````
getWithDefault
(
key
:
key
value
:
value
map
:
Map(key, value)
)
:
value

Gets the value for the given key of the given map using the given value as fallback.

``````(Map.empty()
|> Map.set("key", "value")
|> Map.getWithDefault("key", "fallback")) == "value"

(Map.empty()
|> Map.getWithDefault("key", "fallback")) == "fallback"
``````
has
(
key
:
k
map
:
Map(k, a)
)
:
Bool

Returns whether or not the map has the given key or not.

``````(Map.empty()
|> Map.set("a", 1)
|> Map.has("a")) == true
``````
isEmpty
(
map
:
Map(k, a)
)
:
Bool

Returns whether or not the map is empty.

``````(Map.empty()
|> Map.isEmpty()) == true

(Map.empty()
|> Map.set("a", "b")
|> Map.isEmpty()) == false
``````
keys
(
map
:
Map(k, a)
)
:
Array(k)

Returns the keys of a map as an array.

``````(Map.empty()
|> Map.set("a", 1)
|> Map.set("b", 2)
|> Map.values()) == ["a", "b"]
``````
map
(
method
:
Function(k, a, b)
map
:
Map(k, a)
)
:
Map(k, b)

Map over the given map with the given function.

``````(Map.empty()
|> Map.set("a", 1)
|> Map.set("b", 2)
|> Map.map((key : String, value : Number) : Number {
value * 2
})
|> Map.values()) == [2,4]
``````
merge
(
map1
:
Map(x, z)
map2
:
Map(x, z)
)
:
Map(x, z)

Merges two maps together where the second has the precedence.

``````a =
Map.empty()
|> Map.set("a", "b")

b =
Map.empty()
|> Map.set("a", "y")

(Map.merge(a, b)
|> Map.get("a")) == Maybe.just("y")
``````
reduce
(
memo
:
memo
method
:
Function(memo, key, value, memo)
map
:
Map(key, value)
)
:
memo

Reduces the map from the left using the given accumulator function.

``````(Map.empty()
|> Map.set("a", 1)
|> Map.set("b", 2)
|> Map.reduce(
0,
(memo : Number, key : String, value : Number) : Number { memo + value })) == 3
``````
set
(
key
:
x
value
:
z
map
:
Map(x, z)
)
:
Map(x, z)

Sets the given value to the given key in the map.

``````Map.empty()
|> Map.set("key", "value")
``````
size
(
map
:
Map(key, value)
)
:
Number

Returns the number of items in the map.

``````(Map.empty()
|> Map.set("a", 1)
|> Map.size()) == 1
``````
sortBy
(
method
:
Function(k, v, b)
map
:
Map(k, v)
)
:
Map(k, v)

Sorts the map using the given function.

``````(Map.empty()
|> Map.set("a", 1)
|> Map.set("b", 2)
|> Map.sortBy((key : String, value : Number) : Number {
value - 100
})
|> Map.values()) == ["b", "a"]
``````
values
(
map
:
Map(k, a)
)
:
Array(a)

Returns the values of a map as an array.

``````(Map.empty()
|> Map.set("a", 1)
|> Map.set("b", 2)
|> Map.values()) == [1, 2]
``````