Map
Functions
Removes the item with the key.
(Map.empty()
|> Map.set("a", 1)
|> Map.delete("a")) == Map.empty()
Removes all keys which match the value.
(Map.empty()
|> Map.set("a", 1)
|> Map.set("b", 1)
|> Map.deleteValues(1)) == Map.empty()
Returns an empty map.
Returns the map as an array of key/value tuples.
(Map.empty()
|> Map.set("a", 1)
|> Map.set("b", 2)
|> Map.entries()) == [{"a", 1}, {"b", 2}]
Returns the first key which is matched by the function.
(Map.empty()
|> Map.set("a", 0)
|> Map.set("b", 1)
|> Map.findKeyBy((value : Number) : Bool {
value == 1
})) == Maybe.just("b")
Converts an array of key/value tuples into a Map.
(Map.empty()
|> Map.set("a", 1)
|> Map.set("b", 2)
) == Map.fromArray([{"a", 1}, {"b", 2}])
Gets the value of the key.
Map.empty()
|> Map.set("key", "value")
|> Map.get("key") == Maybe.just("value")
Gets the value of the key using the value as fallback.
(Map.empty()
|> Map.set("key", "value")
|> Map.getWithDefault("key", "fallback")) == "value"
(Map.empty()
|> Map.getWithDefault("key", "fallback")) == "fallback"
Returns whether or not the map has the key.
(Map.empty()
|> Map.set("a", 1)
|> Map.has("a")) == true
Returns whether or not the map is empty.
(Map.empty()
|> Map.isEmpty()) == true
(Map.empty()
|> Map.set("a", "b")
|> Map.isEmpty()) == false
Returns the keys of a map as an array.
(Map.empty()
|> Map.set("a", 1)
|> Map.set("b", 2)
|> Map.values()) == ["a", "b"]
Maps over the keys/values pairs with the function.
(Map.empty()
|> Map.set("a", 1)
|> Map.set("b", 2)
|> Map.map((key : String, value : Number) : Number { value * 2 })
|> Map.values()) == [2,4]
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")
Reduces the map from the left using the 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
Assigns the value to the key in the map.
Map.empty()
|> Map.set("key", "value")
Returns the number of items in the map.
(Map.empty()
|> Map.set("a", 1)
|> Map.size()) == 1
Sorts the map using the function.
(Map.empty()
|> Map.set("a", 1)
|> Map.set("b", 2)
|> Map.sortBy((key : String, value : Number) : Number {
value - 100
})
|> Map.values()) == ["b", "a"]
Returns the values of a map as an array.
(Map.empty()
|> Map.set("a", 1)
|> Map.set("b", 2)
|> Map.values()) == [1, 2]