@head @module std @title Interfaces

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

Interface Sequence<T>

@class-hidden Sequence

An object that implements Sequence can be used as a read-only sequence. The interface includes the following operations: @fun length() as Int @desc Return the length of the sequence. @end @op sequence[n] @optype{Sequence[Int] -> T} @desc 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. @end @end

@ref{Array} and @ref{Str} implement Sequence. Note that Array objects are mutable.

Interface Iterable<T>

@class-hidden Iterable

Iterable objects provide the iterator method: @fun iterator() as Iterator @desc Return an iterator that iterates over all the objects in a composite object. @end

@ref{Str}, @ref{Range}, @ref{Array}, @ref{Map}, @ref{Set} and @ref{Stream} objects implement Iterable.

Interface Iterator<T>

@class-hidden Iterator

An object that supports the Iterator interface performs an iteration over the items of a composite object. It provides these methods: @fun hasNext() as Boolean @desc Return a boolean indicating whether there are additional objects in the iteration. @end @fun next() as T @desc 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 @ref{Array}, guarantee a specific iteration order. @end

Interface Comparable<T>

@class-hidden Comparable @op o < x @optype{Comparable < T -> Boolean} @op o > x @optype{Comparable > T -> Boolean} @desc A Comparable object supports comparisons using < and >. @end

Interface Addable<OT, RT>

@class-hidden Addable @op o + x @optype{Multipliable + OT -> RT} @desc An instance that implements Addable supports the + operation. The operand and result types depend are derived from the type arguments. @end

Interface Multipliable<OT, RT>

@class-hidden Multipliable @op o * x @optype{Multipliable * OT -> RT} @desc An instance that implements Multipliable supports the * operation. The operand and result types depend are derived from the type arguments. @end