Set
dict
An unordered collection of unique elements backed by a Dictionary.
Elements can be any object that responds to hash and =. Duplicate
additions are silently ignored. Use add:, remove:, includes: for
basic operations and do:, select:, reject: for iteration.
Core operations (new, add:, remove:, includes:, size,
isEmpty, do:) are implemented as VM primitives. This file adds
convenience methods on top.
Set new size >>> 0
Set new isEmpty >>> true
"Build a set and check membership"
| s <Set> |
s := Set new.
s add: 1.
s add: 2.
s add: 1.
s size
Class Methods
primitives
Create a new empty set.
Instance Methods
primitives
Add element to the set. Returns self.
Evaluate block once for each element.
Return true if the set contains element.
Return true if the set is empty.
Remove element from the set.
Return the number of elements.
uncategorized
Return a new Array with block applied to each element.
s := Set new. s add: 1. s add: 2.
(s collect: [:x | x * 10]) size >>> 2
Return a human-readable string representation.
Return a new Set excluding elements for which block returns true.
s := Set new. s add: 1. s add: 2. s add: 3. s add: 4.
odds := s reject: [:x | x even].
odds size >>> 2
odds includes: 1 >>> true
odds includes: 3 >>> true
Return a new Set containing only elements for which block returns true.
s := Set new. s add: 1. s add: 2. s add: 3. s add: 4.
evens := s select: [:x | x even].
evens size >>> 2
evens includes: 2 >>> true
evens includes: 4 >>> true