4.34. kink/container/ORDERED_SET

4.34.1. type ordered_set

`ordered_set` is a subtype of `set` type which supports ordering of elements.

The ordering is defined by each `ordered_set` implementation.

See kink/container/SET for `set` type.

The following builtin mods provide ordered_set implementations:

• kink/container/FLAT_SET

• kink/container/TREE_SET

4.34.1.1. S.each($consume_elem)

`each` calls $consume_elem with each element of the the set, in the ordering of the set.

This method suffices the contract of Set.each.

4.34.1.2. S.iter

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

This method suffices the contract of Set.iter.

4.34.1.3. S.fold(Init $combine)

`fold` accumulates elements of the set seeded by `Init`.

If the elements of the 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).

This method suffices the contract of Set.fold.

4.34.1.4. S.reduce($combine)

`reduce` accumulates elements of the set mutually, then returns a maybe tuple.

If the 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 set has a single element `E`, this method returns [E].

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

This method suffices the contract of Set.reduce.

4.34.1.5. S.front

`front` returns the element which comes first in the ordering of the set.

Precondition:

• The set must not be empty

Example:

:TREE_SET.require_from('kink/container/')

:Set <- TREE_SET.of('foo' 'bar' 'baz')
stdout.print_line(Set.front.repr) # => "bar"

4.34.1.6. S.back

`back` returns the element which comes last in the ordering of the set.

Precondition:

• The set must not be empty

Example:

:TREE_SET.require_from('kink/container/')

:Set <- TREE_SET.of('foo' 'bar' 'baz')
stdout.print_line(Set.back.repr) # => "foo"

4.34.1.7. S.pop_front

`pop` pops the element which comes first in the ordering of the set.

Precondition:

• The set must not be empty.

Example:

:FLAT_SET.require_from('kink/container/')

:Set <- FLAT_SET.of('foo' 'bar' 'baz')
:Front <- Set.pop_front
stdout.print_line(Front.repr) # => "bar"
stdout.print_line(Set.repr)   # => Flat_set("baz" "foo")

4.34.1.8. S.pop_back

`pop_back` pops the element which comes last in the ordering of the set.

Precondition:

• The set must not be empty.

Example:

:FLAT_SET.require_from('kink/container/')

:Set <- FLAT_SET.of('foo' 'bar' 'baz')
:Back <- Set.pop_back
stdout.print_line(Back.repr)  # => "foo"
stdout.print_line(Set.repr)   # => Flat_set("bar" "baz")

4.34.1.9. S.iter_from(Min)

`iter_from` returns an iter which iterates over elements equivalent to or bigger than `Min` in the ordering of the set.

Precondition:

• Ordering between `Min` and elements of the set must be able to be tested.

Example:

:TREE_SET.require_from('kink/container/')

:Set <- TREE_SET.of('foo' 'bar' 'baz' 'qux')

Set.iter_from('baz').each{(:E) stdout.print_line(E.repr) }
# Output:
#   "baz"
#   "foo"
#   "qux"

Set.iter_from('bazzz').each{(:E) stdout.print_line(E.repr) }
# Output:
#   "foo"
#   "qux"

Set.iter_from('foo').each{(:E) stdout.print_line(E.repr) }
# Output:
#   "foo"
#   "qux"

Set.iter_from('foooo').each{(:E) stdout.print_line(E.repr) }
# Output:
#   "qux"

4.34.2. ORDERED_SET.is?(Val)

`is?` returns whether `Val` is an ordered_set.