Try Install Learn Blog API Packages GitHub
Pages

Set

Functions for the Set data structure which represents a set of unique values.

Functions

add
(
value
:
a
set
:
Set(a)
)
:
Set(a)

Adds the given value to the set.

(Set.empty()
|> Set.add("value")) == Set.fromArray(["value"])
delete
(
value
:
a
set
:
Set(a)
)
:
Set(a)

Deletes the given value from the set.

(Set.empty()
|> Set.add("value")
|> Set.delete("value")) == Set.empty()
empty
:
Set(a)

Returns an empty set.

fromArray
(
array
:
Array(a)
)
:
Set(a)

Converts an Array to a Set.

(Set.empty()
|> Set.add("value")) == Set.fromArray(["value"])
has
(
value
:
a
set
:
Set(a)
)
:
Bool

Returns whether or not the given set has the given value.

(Set.empty()
|> Set.add(Maybe.just("value"))
|> Set.has(Maybe.just("value"))) == true
map
(
method
:
Function(a, b)
set
:
Set(a)
)
:
Set(b)

Maps over the items of the set to return a new set.

(Set.fromArray([0])
|> Set.map(Number.toString)) == Set.fromArray(["0"])
size
(
set
:
Set(a)
)
:
Number

Returns the size of a set

Set.size(Set.fromArray([0,1,2])) == 3
toArray
(
set
:
Set(a)
)
:
Array(a)

Converts the Set to an Array.

(Set.empty()
|> Set.add("value")
|> Set.toArray()) == ["value"]