SetsealedThe insertion-ordered collection of unique values, written #<1 2 3>. Adding an element that is already present is a no-op.
Membership is hash-indexed: an element's hash runs once, at insert, and lookup uses the same equality ladder as Map keys — by value for scalars and strings, by identity for user instances unless their class overrides both hash and ==:. A set with a checked element type comes from Set.of: / ensure:.
Sets are iterable (each: is implemented natively - Set#each: in src/runtime/set.rs) and carry the set-algebra operations, built on the native add:/contains?: and the Iterate combinators.
A Set serializes as a List in insertion order (the formats have no set type); it comes back as a List — rebuild with Set.of: if set-ness matters.
A fresh empty Set, the Set class default.
A fresh empty set — the same value the #<> literal builds.
Always refused: a Set has no instance fields for a new: config block to set. Construct with #< >, Set.new, or Set.of:.
A fresh empty set tagged with an element class: every later add: is checked, raising a catchable TypeError on a mismatch.
(Set.of:String).elementType "* -> String
Same-elements equality: true when the other value is a Set of the same size containing every element of this one — insertion order does not matter. Anything that is not a Set answers false.
#<1 2 3> == #<3 2 1> "* -> true
Add a value; one already present is left alone (a set holds one of each). Answers the receiver. On a tagged set (Set.of:) the value is checked first.
#<1 2>.add:3 "* -> #<1 2 3> #<1 2>.add:2 "* -> #<1 2>
A fresh empty LIST carrying this set's element tag — the Iterate mixin's staging collection, where transforms like collect: accumulate results in order before they become the final collection.
True when the value is an element — an O(1) hash probe, using the same equality ladder as Map keys.
#<1 2 3>.contains?:2 "* -> true #<1 2 3>.contains?:9 "* -> false
The number of elements.
#<1 2 3>.count "* -> 3
A new Set holding the elements of self that are not in other.
#<1 2 3>.difference:#<2> "* -> #<1 3>
Call a block once per element, in insertion order; answers the receiver. This is the one iteration primitive — the whole Iterate surface (collect:, select:, …) derives from it.
The checked element type as a Symbol, or nil for an ordinary untagged set.
(Set.of:String).elementType "* -> String
A fresh empty set like the receiver — element tag included. The species hook the Iterate mixin uses, so transforms of a checked set stay checked.
Check every element against a class and answer a NEW set carrying that element tag; a non-matching element raises a catchable TypeError. Cached hashes carry over, so instance hash methods do not re-run.
(#<1 2>.ensure:Integer).elementType "* -> Integer
A new Set holding the elements present in both self and other.
#<1 2 3>.intersection:#<2 3 4> "* -> #<2 3>
Remove a value if present (a miss is a no-op); answers the receiver. The remaining elements keep their insertion order.
#<1 2 3>.remove:2 "* -> #<1 3>
The display string: #< and > around each element's .s, space-separated, in insertion order.
#<1 2 3>.s "* -> #<1 2 3>
True when every element of self is in other.
#<1 2>.subset?:#<1 2 3> "* -> true
True when every element of other is in self.
#<1 2 3>.superset?:#<2> "* -> true
A new Set holding every element of self and other.
#<1 2>.union:#<2 3> "* -> #<1 2 3>