The std module defines several interfaces. They are described in this section. Note that a class may implement multiple interfaces.
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.
Iterable objects provide the iterator method:
- iterator() as Iterator<T>
- Return an iterator that iterates over all the objects in a composite object.
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.
- o < x (Comparable<T> < T ⇒ Boolean)
- o > x (Comparable<T> > T ⇒ Boolean)
- A Comparable object supports comparisons using < and >.
Interface Addable<OT, RT>
- o + x (Addable<OT, RT> + OT ⇒ RT)
- 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> * OT ⇒ RT)
- An instance that implements Multipliable supports the * operation. The operand and result types are derived from the type arguments.