5.35. kink/container/ORDERED_SET

5.35.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

5.35.1.1. Set.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.

5.35.1.2. Set.iter(...[Min])

`iter` returns an iter which iterates over elements in the ordering of the set. If `Min` is given, the iter has elements equivalent to or bigger than `Min`. If `Min` is not given, the iter has all elements of `Set`.

Precondition

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

Example

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

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

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

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

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

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

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

This method extends the contracts of Set.iter.

5.35.1.3. Set.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.

5.35.1.4. Set.reduce($combine ...[$empty_fallback])

`reduce` accumulates elements of `Set` mutually.

If `Set` has elements E1, E2, E3, ,,, En_1, En, in the ordering of the set, `reduce` tail-calls combine(combine(,,,combine(combine(E1 E2) E3),,, En_1) En).

If `Set` has a single element `E`, `reduce` returns `E`.

If `Set` is empty, and $empty_fallback is given, `reduce` tail-calls $empty_fallback with no arg.

If `Set` is empty, and $empty_fallback is not given, `reduce` raises an exception.

This method suffices the contract of Set.reduce.

5.35.1.5. Set.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"

5.35.1.6. Set.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"

5.35.1.7. Set.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")

5.35.1.8. Set.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")

5.35.2. ORDERED_SET.is?(Val)

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