Set[T]
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.
Inherits from: Iterable[T]
Implements: Spread[T]
Constructor
Set …
Builds a set, from one iterable if given.
Parameters
| Name | Type | Description |
|---|---|---|
iterable? |
Iterable[T] |
Fields
len @ Int[get]Returns the number of members.
Methods
(iter)() -> Iter[T]
Iterates values in insertion order:
Returns an iterator.(spread)() -> Spread[T]
Spreads the values positionally, in insertion order.
add value
Adds value if it is not already present.
Parameters
| Name | Type | Description |
|---|---|---|
value |
T |
the value to insert |
Example
clear()
Removes all members.
contains value -> Bool
Tests whether the Set contains value.
Parameters
| Name | Type | Description |
|---|---|---|
value |
Value |
the value to test |
copy() -> Set[T]
Returns a shallow copy of the Set.
Insertion order is preserved. Contained values are not recursively copied.
delete value -> Bool
Indicates whether a value was removed. Removes value if present.
Parameters
| Name | Type | Description |
|---|---|---|
value |
Value |
the value to remove |
diff[U] other -> Set[T]
Returns a new Set containing members from the receiver that are not present in
other.
Parameters
| Name | Type | Description |
|---|---|---|
other |
Set[U] |
other Set |
intersect[U] other -> Set[T]
Returns a new Set containing members that are present in both sets, in the receiver's insertion order.
Parameters
| Name | Type | Description |
|---|---|---|
other |
Set[U] |
other Set |
is_subset[U] other -> Bool
Returns true when every member of the receiver is present in other.
Parameters
| Name | Type | Description |
|---|---|---|
other |
Set[U] |
other Set |
is_superset[U] other -> Bool
Returns true when every member of other is present in the receiver.
Parameters
| Name | Type | Description |
|---|---|---|
other |
Set[U] |
other Set |
sym_diff[U] other -> Set[Union[T, U]]
Returns a new Set containing members present in exactly one of the two sets.
Parameters
| Name | Type | Description |
|---|---|---|
other |
Set[U] |
other Set |
union[U] other -> Set[Union[T, U]]
Returns a new Set containing all members from self, then first-seen members
from other.
Parameters
| Name | Type | Description |
|---|---|---|
other |
Set[U] |
other Set |