Collections

A collection in which each distinct element occurs at most once. Two non-identical values are considered distinct only if they are unequal, according to their own definition of value equality.

A `Set` is a `Collection` of its elements. Sets may not have null elements.

A new `Set` may be obtained by calling the function `set()`.

    value words = set { "hello", "world" };
    value greetings = set { "hello", "goodbye", "hola", "adios" };

Sets may be the subject of the binary union, intersection, and complement operators `|`, `&`, and `~`.

    value greetingsInWords = words & greetings;
    value allWords = words | greetings;

An implementation of `Set` may compare elements for equality using `Object.equals()` or `Comparable.compare()`.

See also `set()`

no type hierarchy

- `Set`
  - `Collection`
    - `Iterable`
      - `Category`

- `Set`
  - `emptySet`

Attributes
`distinct` | Source Code `shared actual {Element*} distinct` A stream that produces every element produced by this stream exactly once. Duplicate elements of this stream are eliminated. Two elements are considered distinct unless they are both null, or unless they are both non-null and equal. For example:
    String("hello world".distinct)
is the string `"helo wrd"`. This is a lazy operation and the resulting stream reflects changes to this stream. Refines `Iterable.distinct`
`hash` | Source Code `shared actual default Integer hash` The hash value of the value, which allows the value to be an element of a hash-based set or key of a hash-based map. Implementations must respect the constraint that: if `x==y` then `x.hash==y.hash`. Therefore, a class which refines `Object.equals()` must also refine `hash`. Because the `Integer` type is platform-dependent a compiler for a given platform is permitted to further manipulate the calculated hash for an object, and the resulting hash may differ between platforms. Refines `Object.hash`

Inherited Attributes
Attributes inherited from: `Object` `hash`, `string`
Attributes inherited from: `Collection<Element>` `empty`, `permutations`, `string`
Attributes inherited from: `Iterable<Element,Absent>` `coalesced`, `cycled`, `distinct`, `empty`, `exceptLast`, `first`, `indexed`, `last`, `paired`, `rest`, `size`, `string`

Methods
`clone` | Source Code `shared formal Set<Element> clone()` A shallow copy of this set, that is, a set with the same elements as this set, which do not change if the elements of this set change. Refines `Collection.clone`
`complement` | Source Code `shared default Set<Element> complement<Other>(Set<Other> set) given Other satisfies Object` Returns a new `Set` containing all the elements in this set that are not contained in the given `Set`. For example:
    set { "hello", "world" } ~ set { 1, 2, "hello" }
Produces the set `{ "world" }` of type `Set<String>`.
`contains` | Source Code `shared actual default Boolean contains(Object element)` The fundamental operation for `Set`s. Determines if the given value belongs to this set. Refines `Collection.contains` ultimately refines `Category.contains`
`defaultNullElements` | Source Code `shared actual {Element*} defaultNullElements<Default>(Default defaultValue) given Default satisfies Object` Produces a stream containing the elements of this stream, in the order in which they occur in this stream, after replacing every `null` element in the stream with the given default value. The value `null` does not ocur in the resulting stream. For example, the expression
    { "123", "abc", "456" }.map(parseInteger).defaultNullElements(0)
results in the stream `{ 123, 0, 456 }`. Refines `Iterable.defaultNullElements`
`equals` | Source Code `shared actual default Boolean equals(Object that)` Two `Set`s are considered equal if they have the same size and if every element of the first set is also an element of the second set, as determined by `contains()`. Equivalently, a set is equal to a second set if it is both a subset and a superset of the second set. Refines `Object.equals`
`exclusiveUnion` | Source Code `shared default Set<Element|Other> exclusiveUnion<Other>(Set<Other> set) given Other satisfies Object` Returns a new `Set` containing only the elements contained in either this set or the given `Set`, but no element contained in both sets.
`intersection` | Source Code `shared default Set<Element&Other> intersection<Other>(Set<Other> set) given Other satisfies Object` Returns a new `Set` containing only the elements that are present in both this set and the given `Set` and that are instances of the intersection `Element&Other` of the element types of the two sets. For example:
    set { "hello", "world" } & set { 1, 2, "hello" }
Produces the set `{ "hello" }` of type `Set<String>`. Note that, according to this definition, and even though `1==1.0` evaluates to true, the expression
    set { 1 } & set { 1.0 }
produces the empty set `{}`.
`subset` | Source Code `shared default Boolean subset(Set<Object> set)` Determines if this set is a subset of the given `Set`, that is, if the given set contains all of the elements in this set.
`superset` | Source Code `shared default Boolean superset(Set<Object> set)` Determines if this set is a superset of the given `Set`, that is, if this set contains all of the elements in the given set.
`union` | Source Code `shared default Set<Element|Other> union<Other>(Set<Other> set) given Other satisfies Object` Returns a new `Set` containing all the elements of this set and all the elements of the given `Set`. For example:
    set { "hello", "world" } | set { 1, 2, "hello" }
Produces the set `{ "hello", "world", 1, 2 }` of type `Set<String|Integer>`. Note that it is possible for two sets of disjoint element type to be considered to have elements in common. For example, since `1==1.0` evaluates to true, the expression
    set { 1 } | set { 1.0 }
produces the set `{ 1 }`.

Inherited Methods
Methods inherited from: `Object` `equals()`
Methods inherited from: `Category<Element>` `contains()`, `containsAny()`, `containsEvery()`
Methods inherited from: `Collection<Element>` `clone()`, `contains()`
Methods inherited from: `Iterable<Element,Absent>` `any()`, `by()`, `chain()`, `collect()`, `contains()`, `count()`, `defaultNullElements()`, `each()`, `every()`, `filter()`, `find()`, `findLast()`, `flatMap()`, `fold()`, `follow()`, `frequencies()`, `getFromFirst()`, `group()`, `indexes()`, `interpose()`, `iterator()`, `locate()`, `locateLast()`, `locations()`, `longerThan()`, `map()`, `max()`, `narrow()`, `partition()`, `product()`, `reduce()`, `repeat()`, `scan()`, `select()`, `sequence()`, `shorterThan()`, `skip()`, `skipWhile()`, `sort()`, `spread()`, `summarize()`, `tabulate()`, `take()`, `takeWhile()`