3.29. kink/container/SET

Operations for sets.

3.29.1. SET.set?(Val)

Returns true if the Val is a set, otherwise false.

3.29.2. Type set

A container that does not contain duplicate elements, that is, no pair of two different elements of a set are equivalent.

Equivalence of elements is defined by each set implementation.

Set.push(Elem)

Inserts an Elem to the Set if the Set does not contain the Elem.

If the set contains an element equivalent to the Elem, it depends on implementation whether the element is replaced by Elem or not.

Set.have?(Elem)

Returns true if the Set contains an equivalent element to the Elem, or returns false.

Set.size

Returns the size of the Set, which is a number of elements.

Set.empty?

Returns true if the Set contains no element, or false if the Set contains one or more elements.

Set.empty?

Returns true if the Set contains one or more elements, or false if the Set contains no element.

Set.subset_of?(Another_set)

Returns true if the Set is a subset of Another_set, that is, Another_set contains every element of the Set.

The equivalence of two sets must be defined as the same.

Set.op_eq(Another_set)

Returns true if the Set is equivalent to Another_set, that is, the Set is a subset of Another_set and Another_set is a subset of the Set.

The equivalence of two sets must be defined as the same.

Set.op_ne(Another_set)

Returns true if the Set is not equivalent to Another_set, that is, the Set is not a subset of Another_set or Another_set is not a subset of the Set.

The equivalence of two sets must be defined as the same.

Set.push_each(Eacher)

Inserts each element to the Set.

If the set contains an element equivalent to one in Eacher, it depends on implementation whether the element is replaced or not.

Set.remove(Elem)

Removes an equivalent element to the Elem when the Set contains it.

If the Set does not contain an element equivalent to the Elem, this method does nothing.

Set.clear

Removes all the elements.

Set.iter

Returns an iter of the elements of the Set.

Set.each($consume_elem)

Calls $consume_elem with each element of the Set.

Set.for_all?($ok?)

Returns true if all the elements of the Set satisfy $ok?. Returns false if at least one element of the Set does not satisfy $ok?.

Set.for_any?($ok?)

Returns true if at least one element of the Set satisfies $ok?. Returns fall if all the elements of the Set does not satisfy $ok?.

Set.count($counted?)

Returns the number of elements of the Set which satisfy $counted?.

Set.fold(Init $combine)

Accumulates elements of the Set seeded by Init.

If the elements of the Set is E1, E2, ,,, En_1, En, in any order, this fun returns combine(combine(,,,combine(combine(Init E1) E2),,, En_1) En).

Set.reduce($combine)

Accumulates elements of the Set mutually, then returns a maybe tuple.

If the Set has elements E1, E2, E3, ,,, En_1, En, in any order, this method returns [combine(combine(,,,combine(combine(E1 E2) E3),,, En_1) En)].

If the Set has a single element E, this method returns [E].

If the Set is empty, this method returns [].

Set.have_all?(For_aller)

Returns true if the Set has all the elements of For_aller.

For_aller must implement .for_all?($ok?).

3.29.3. SET.ordered_set?(Val)

Returns true if the Val is a ordered_set, otherwise false.

3.29.4. Type ordered_set

A subtype of set which supports ordering of elements.

The ordering is defined by each ordered_set implementation.

Ordered_set.each($consume_elem)

Calls $consume_elem with each element of the Ordered_set, in the ordering of the set.

Ordered_set.iter

Returns an iter which iterates over all the elements in the ordering of the set.

Ordered_set.fold(Init $combine)

Accumulates elements of the Ordered_set seeded by Init.

If the elements of the Ordered_set is E1, E2, ,,, En_1, En, in the ordering of the set, this fun returns combine(combine(,,,combine(combine(Init E1) E2),,, En_1) En).

Ordered_set.reduce($combine)

Accumulates elements of the Ordered_set mutually, then returns a maybe tuple.

If the Ordered_set has elements E1, E2, E3, ,,, En_1, En, in the ordering of the set, this method returns [combine(combine(,,,combine(combine(E1 E2) E3),,, En_1) En)].

If the Ordered_set has a single element E, this method returns [E].

If the Ordered_set is empty, this method returns [].

Ordered_set.front

Returns the element which comes first in the ordering of the set.

Precondition: the set must not be empty.

Ordered_set.back

Returns the element which comes last in the ordering of the set.

Precondition: the set must not be empty.

Ordered_set.pop_front

Pops the element which comes first in the ordering of the set.

Precondition: the set must not be empty.

Ordered_set.pop_back

Pops the element which comes last in the ordering of the set.

Precondition: the set must not be empty.

Ordered_set.iter_from(Min)

Returns an iter which iterates over element equivalent to or bigger than the Min in the ordering of the set.

3.29.5. SET.factory($_new_empty_set)

Makes a set_factory.

$_new_empty_set is a thunk to make a new empty set. Methods of the factory use this thunk to make a set.

Example:

:TREE_SET.require_from('kink/container/')
:Factory = SET.factory{ TREE_SET.of() }
:Union = Factory.union(
  TREE_SET.of('foo' 'bar' 'baz')
  TREE_SET.of('bar' 'baz' 'qux')
)
stdout.print_line(Union.repr) # => Tree_set("bar" "baz" "foo" "qux")

3.29.6. SET.set_factory?(Val)

Returns true if Val is a set_factory, or false.

3.29.7. Type set_factory

Factory of sets.

Set_factory.of(...Elems)

Makes a set containing each element of the Elems.

Set_factory.of_each(Eacher)

Makes a set containing each element of the Eacher.

Set_factory.union(...Sets)

Makes a union set of Sets.

Set_factory.intersect(First_set ...Rest_sets)

Makes an intersect set of First_set and each set of Rest_sets.

Set_factory.except(First_set ...Rest_sets)

Makes a set containing each element of First_set which is not a member of any set of Rest_sets.

Set_factory.repr

Makes a str representation of Set_factory, such as "Set_factory(,,,)".