class Set[out T]
include Enumerable[T]
An immutable set: each value at most once, compared with == and
hash.
A set keeps insertion order, as Ruby's does: iteration, #to_a and
#inspect list the members in the order they were first added. The
updating methods (#add, #delete, #| ...) return a new set and leave
the receiver as it was; Set::Builder is the mutable one. Equality does
not depend on the order.
s = Set[3, 1, 3, 2]
s # => Set[3, 1, 2]
s.add(4) # => Set[3, 1, 2, 4]
s.include?(4) # => false
s | Set[5, 1] # => Set[3, 1, 2, 5]
s == Set[1, 2, 3] # => true
<prelude>:4762
Classes and modules
Set::BuilderA mutable set, for building a Set in place.
Class methods
def self.new -> Set[T]
An empty set, as Set[Int].new.
<prelude>:4767
def self.[](*items: T) -> Set[T]
A set of items, in the order first given, without duplicates.
<prelude>:4769
def self.build(&: (Set::Builder[T]) -> Void) -> Set[T]
Calls the block with a new Set::Builder and returns what it holds
afterwards.
<prelude>:4772
def self.new(items: Array[T]) -> Set[T]
A set of the elements of items, in the order first given, without
duplicates.
Set.new([2, 1, 2]) # => Set[2, 1]
<prelude>:4848
Methods
def each(&: (T) -> Void) -> Void
Calls the block with each member, in insertion order.
<prelude>:4775
def add[U >: T](value: U) -> Set[U]
The set with value added: last when it is new, the same members when
it is already one.
<prelude>:4778
def delete(value: Object) -> Set[T]
The set without value, or the same members when it is none.
<prelude>:4780
def include?(value: Object) -> Bool
Whether value is a member. A value of another type than the members'
is none.
<prelude>:4783
def size -> Int
The number of members.
<prelude>:4785
def length -> Int
The number of members: the same as #size.
<prelude>:4787
def empty? -> Bool
Whether there is no member.
<prelude>:4789
def |[U >: T](other: Set[U]) -> Set[U]
The union: the members of self, then those of other that are new, in
their order.
<prelude>:4792
def &(other: Set[Object]) -> Set[T]
The intersection: the members of self that are in other, in the order
of self.
Set[3, 1, 2] & Set[2, 3, 9] # => Set[3, 2]
<prelude>:4799
def -(other: Set[Object]) -> Set[T]
The difference: the members of self that are not in other.
<prelude>:4801
def ^[U >: T](other: Set[U]) -> Set[U]
The members in exactly one of the two sets: those of self first, then
those of other.
Set[1, 2, 3] ^ Set[3, 4] # => Set[1, 2, 4]
<prelude>:4808
def subset?(other: Set[Object]) -> Bool
Whether every member is in other. A set is a subset of itself.
<prelude>:4810
def superset?(other: Set[Object]) -> Bool
Whether every member of other is in self. A set is a superset of
itself.
<prelude>:4813
def proper_subset?(other: Set[Object]) -> Bool
Whether every member is in other, which has more.
<prelude>:4815
def proper_superset?(other: Set[Object]) -> Bool
Whether every member of other is in self, which has more.
<prelude>:4817
def disjoint?(other: Set[Object]) -> Bool
Whether the two sets have no member in common.
<prelude>:4819
def intersect?(other: Set[Object]) -> Bool
Whether the two sets have a member in common.
<prelude>:4821
def merge[U >: T](items: Array[U]) -> Set[U]
The set with the elements of items added, in their order. Unlike
Ruby's, it returns a new set.
<prelude>:4824
def add?[U >: T](value: U) -> Set[U]?
The set with the value added, or nil when it was already a member.
<prelude>:4826
def select(&: (T) -> Object) -> Set[T]
The members the block is truthy for, in order.
<prelude>:4828
def reject(&: (T) -> Object) -> Set[T]
The set without the members the block is truthy for.
<prelude>:4830
def to_a -> Array[T]
The members, in insertion order.
<prelude>:4832
def to_s -> String
The literal form, as #inspect.
<prelude>:4834
def inspect -> String
The literal form, in insertion order, as Set[1, 2].
<prelude>:4836
def ==(other: Object) -> Bool
Whether other is a set with the same members, whatever their order.
<prelude>:4838
def hash -> Int
A hash code consistent with #==, so the same whatever the order of the
members.
<prelude>:4841
def +[U >: T](other: Set[U]) -> Set[U]
The union: the same as #|.
<prelude>:4850
def union[U >: T](other: Set[U]) -> Set[U]
The union: the same as #|.
<prelude>:4852
def intersection(other: Set[Object]) -> Set[T]
The intersection: the same as #&.
<prelude>:4854
def difference(other: Set[Object]) -> Set[T]
The difference: the same as #-.
<prelude>:4856
def <=(other: Set[Object]) -> Bool
Whether every member is in other: the same as #subset?.
<prelude>:4858
def >=(other: Set[Object]) -> Bool
Whether every member of other is in self: the same as #superset?.
<prelude>:4860
def <(other: Set[Object]) -> Bool
Whether self is a proper subset of other: the same as
#proper_subset?.
<prelude>:4863
def >(other: Set[Object]) -> Bool
Whether self is a proper superset of other: the same as
#proper_superset?.
<prelude>:4866
def member?(value: Object) -> Bool
Whether value is a member: the same as #include?.
<prelude>:4868
def filter(&: (T) -> Object) -> Set[T]
The members the block is truthy for: the same as #select.
<prelude>:4870
def delete_if(&: (T) -> Object) -> Set[T]
The set without the members the block is truthy for: the same as
#reject. The receiver is not changed, unlike Ruby's.
<prelude>:4873
def keep_if(&: (T) -> Object) -> Set[T]
The members the block is truthy for: the same as #select. The receiver
is not changed, unlike Ruby's.
<prelude>:4876