Set:
Filter:
Classes | Collections > Unordered

Set : Collection : Object

a set according to equality
Source: Set.sc
Subclasses: Dictionary, IdentitySet

Description

A Set is s collection of objects, no two of which are equal. Most of its methods are inherited from Collection. The contents of a Set are unordered. You must not depend on the order of items in a set. For an ordered set, see OrderedIdentitySet.

Class Methods

Inherited class methods

Undocumented class methods

Set.new(n: 2)

Instance Methods

Adding and Removing

.add(item)

Add an Object to the Set. An object which is equal to an object already in the Set will not be added.

.remove(item)

Remove an Object from the Set. Element is checked for equality (not for identity).

Testing

.includes(item)

Returns true if the specified item is present in the Set. Elements are checked for equality (not for identity).

.findMatch(item)

Returns the item, if it is present in the set. Otherwise returns nil. Element is checked for equality (not for identity).

Iteration

.do(function)

Evaluates function for each item in the Set. The function is passed two arguments, the item and an integer index.

.keyAt(index)

Returns the object at the internal index. This index is not deterministic.

Set specific operations

.sect(that)

&(that)

Return the set theoretical intersection of this and that. The function will search for objects occurring in both sets and return a new set containing those. Elements are checked for equality (not for identity).

.union(that)

|(that)

Return the set theoretical union of this and that. The function combines the two sets into one without duplicates. Elements are checked for equality (not for identity).

.difference(that)

-(that)

Return the set of all items which are elements of this, but not of that. Elements are checked for equality (not for identity).

.symmetricDifference(that)

--(that)

Return the set of all items which are not elements of both this and that. Elements are checked for equality (not for identity).

.isSubsetOf(that)

Returns true if all elements of this are also elements of that. Elements are checked for equality (not for identity). Since Set is an unordered collection, order doesn't matter in this comparison.

Inherited instance methods

Undocumented instance methods

.array

.array = value

.asSet

.choose

.clear

.copy

.fixCollisionsFrom(index)

.makeEmpty

.pop

.scanFor(obj)

.size

.species

.unify

Examples