Try Install Learn Blog API Packages GitHub
Pages
core

Search
Entities

Map

Functions

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

Removes the item with the key.

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

Removes all keys which match the value.

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

Returns an empty map.

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

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}]
findKeyBy
(
map
:
Map(key, value)
function
:
Function(value, Bool)
)
:
Maybe(key)

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")
fromArray
(
array
:
Array(Tuple(a, b))
)
:
Map(a, 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}])
get
(
map
:
Map(key, value)
search
:
key
)
:
Maybe(value)

Gets the value of the key.

Map.empty()
|> Map.set("key", "value")
|> Map.get("key") == Maybe.just("value")
getWithDefault
(
map
:
Map(key, value)
key
:
key
value
:
value
)
:
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"
has
(
map
:
Map(key, value)
search
:
key
)
:
Bool

Returns whether or not the map has the key.

(Map.empty()
|> Map.set("a", 1)
|> Map.has("a")) == true
isEmpty
(
map
:
Map(key, value)
)
:
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(key, value)
)
:
Array(key)

Returns the keys of a map as an array.

(Map.empty()
|> Map.set("a", 1)
|> Map.set("b", 2)
|> Map.values()) == ["a", "b"]
map
(
map
:
Map(key, value)
function
:
Function(key, value, result)
)
:
Map(key, result)

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]
merge
(
map1
:
Map(key, value)
map2
:
Map(key, value)
)
:
Map(key, value)

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
(
map
:
Map(key, value)
memo
:
memo
method
:
Function(memo, key, value, memo)
)
:
memo

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
set
(
map
:
Map(key, value)
key
:
key
value
:
value
)
:
Map(key, value)

Assigns the value to the 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
(
map
:
Map(key, value)
method
:
Function(key, value, result)
)
:
Map(key, value)

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"]
values
(
map
:
Map(key, value)
)
:
Array(value)

Returns the values of a map as an array.

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