Set
Sets are ordered, mutable collections with unique membership semantics.
Iteration preserves insertion order. Reinserting an existing value is a no-op and does not move it to the end.
Constructor
Set iterable
Builds a set from one iterable.
Fields
len
Returns the number of members.
Type
Methods
add value
Adds value if it is not already present.
Parameters
| Name | Type | Description |
|---|---|---|
value |
the value to insert |
delete value
Removes value if present.
Parameters
| Name | Type | Description |
|---|---|---|
value |
the value to remove |
Returns
Bool indicating whether a value was removed
clear
Removes all members.
copy
Returns a shallow copy of the Set.
Insertion order is preserved. Contained values are not recursively copied.
Returns
contains value
Tests whether the Set contains value.
Parameters
| Name | Type | Description |
|---|---|---|
value |
the value to test |
Returns
union other
Returns a new Set containing all members from self, then first-seen members
from other.
Parameters
| Name | Type | Description |
|---|---|---|
other |
Set |
other Set |
Returns
intersect other
Returns a new Set containing members that are present in both sets, in the receiver's insertion order.
Parameters
| Name | Type | Description |
|---|---|---|
other |
Set |
other Set |
Returns
diff other
Returns a new Set containing members from the receiver that are not present in
other.
Parameters
| Name | Type | Description |
|---|---|---|
other |
Set |
other Set |
Returns
sym_diff other
Returns a new Set containing members present in exactly one of the two sets.
Parameters
| Name | Type | Description |
|---|---|---|
other |
Set |
other Set |
Returns
is_subset other
Returns true when every member of the receiver is present in other.
Parameters
| Name | Type | Description |
|---|---|---|
other |
Set |
other Set |
Returns
is_superset other
Returns true when every member of other is present in the receiver.
Parameters
| Name | Type | Description |
|---|---|---|
other |
Set |
other Set |
Returns
Operations
Iteration
Iterating a Set yields values in insertion order: