Std.Set
View source →Sets represented as maps with true values.
Every function delegates to Std.Map / Std.List, keeping the
implementation trivial and the representation directly inspectable.
Examples
use Std.Set
let s = add(:x, add(:y, new()))
member(:x, s) # => true
size(s) # => 2
use Std.Set
let a = from_list([1, 2, 3])
let b = from_list([2, 3, 4])
to_list(intersection(a, b)) # => [2, 3]
to_list(difference(a, b)) # => [1]
Functions
-
# fn __group__() -> Atom
Group tag consumed by
Cure.Stdlib.Preload. -
# fn add(elem: T, set: Map(Any, Any)) -> Map(Any, Any)
Insert
elemintoset. -
# fn difference(a: Map(Any, Any), b: Map(Any, Any)) -> Map(Any, Any)
Set difference
a \ b. -
# fn from_list(list: List(T)) -> Map(Any, Any)
Build a set from a list of elements; duplicates collapse.
-
# fn intersection(a: Map(Any, Any), b: Map(Any, Any)) -> Map(Any, Any)
Set intersection.
-
# fn is_empty(set: Map(Any, Any)) -> Bool
truewhen the set has no elements. -
# fn member(elem: T, set: Map(Any, Any)) -> Bool
truewhenelemis a member ofset. -
# fn new() -> Map(Any, Any)
New empty set.
-
# fn remove(elem: T, set: Map(Any, Any)) -> Map(Any, Any)
Remove
elemfromset; no-op if absent. -
# fn size(set: Map(Any, Any)) -> Int
Number of elements in
set. -
# fn to_list(set: Map(Any, Any)) -> List(T)
List of elements in the set (order is
:maps.keys/1-defined). -
# fn union(a: Map(Any, Any), b: Map(Any, Any)) -> Map(Any, Any)
Set union.