Sets can be checked for member existence:
Sets contain distinct values:
Sets can be added to easily:
Two sets can be intersected easily:
Two sets can be joined as their union easily:
The difference between two sets can be obtained easily:
Set elements can be removed easily:
Set equivalency is independent of order:
Sets may be of mixed type:
Set elements can be removed in multiple:
Set
s are Iterable
s that contain no duplicate elements.
Set
s are Iterable
s that contain no duplicate elements. The operations on sets are summarized in the following table for general sets and in the table after that for mutable sets. They fall into the following categories:
contains
, apply
, subsetOf
. The contains
method asks whether a set contains a given element. The apply
method for a set is the same as contains
, so set(elem)
is the same as set contains elem
. That means sets can also be used as test functions that return true for the elements they contain.+
and ++
, which add one or more elements to a set, yielding a new set.-
, --
, which remove one or more elements from a set, yielding a new set.intersect
, union
, and diff
, whereas the symbolic versions are &
, |
, and &~
. In fact, the ++
that Set inherits from Traversable
can be seen as yet another alias of union
or |
, except that ++
takes a Traversable
argument whereas union
and |
take sets.Sets can be created easily:
Attempted removal of nonexistent elements from a set is handled gracefully:
A set is either a subset of another set or it isn't:
Set elements can be removed with a tuple:
The parameterless execute method has been deprecated and will be removed in a future version of ScalaTest. Please invoke execute with empty parens instead: execute().
The trap method is no longer needed for demos in the REPL, which now abreviates stack traces, and will be removed in a future version of ScalaTest