Map
Functions
Removes the given key from the map
(Map.empty()
|> Map.set("a", 1)
|> Map.delete("a")) == Map.empty()
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()
Returns an empty map.
Returns the array of {key, value} Tuple.
(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 given function.
(Map.empty()
|> Map.set("a", 0)
|> Map.set("b", 1)
|> Map.findKey((value : Number) : Bool {
value == 1
})) == Maybe.just("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}])
Gets the value for the given key of the given map.
Map.empty()
|> Map.set("key", "value")
|> Map.get("key") == Maybe.just("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"
Returns whether or not the map has the given key or not.
(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"]
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]
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 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
Sets the given value to the given 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 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"]
Returns the values of a map as an array.
(Map.empty()
|> Map.set("a", 1)
|> Map.set("b", 2)
|> Map.values()) == [1, 2]