Interfaces

The std module defines several interfaces. They are described in this section. Note that a class may implement multiple interfaces.

Interface Sequence<T>

An object that implements Sequence can be used as a read-only sequence. The interface includes the following operations:

length() as Int
Return the length of the sequence.
sequence[n] (Sequence<T>[Int] ⇒ T)
Return the element at the specified index. The first element has index 0, the second 1, etc.

Note: Negative index values need not be supported.

Array and Str implement Sequence. Note that Array objects are mutable.

Interface Iterable<T>

Iterable objects provide the iterator method:

iterator() as Iterator<T>
Return an iterator that iterates over all the objects in a composite object.

Str, Range, Array, Map, Set and Stream objects implement Iterable.

Interface Iterator<T>

An object that supports the Iterator interface performs an iteration over the items of a composite object. It provides these methods:

hasNext() as Boolean
Return a boolean indicating whether there are additional objects in the iteration.
next() as T
Return the next object in the iteration. The iterator interface does not specify the order in which objects are returned, but many iterable types, such as Array, guarantee a specific iteration order.

Interface Comparable<T>

o < x (Comparable<T> < TBoolean)
o > x (Comparable<T> > TBoolean)
A Comparable object supports comparisons using < and >.

Interface Addable<OT, RT>

o + x (Addable<OT, RT> + OTRT)
An instance that implements Addable supports the + operation. The operand and result types are derived from the type arguments.

Interface Multipliable<OT, RT>

o * x (Multipliable<OT, RT> * OTRT)
An instance that implements Multipliable supports the * operation. The operand and result types are derived from the type arguments.