Implicit interfaces
A few implicit interfaces are referred to in Alore documentation. They are described in this section. Note that an object (or type) may support multiple implicit interfaces. Note that implicit interfaces are often called simply interfaces.
Sequence
An object supports the read-only sequence interface if it supports the following operations:
- length()
- Return the length of the sequence.
- sequence[n]
- 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.
Mutable sequences support assigning to an index as well. It is valid to refer to the sequence interface without specifying whether the sequence is read-only or mutable. The exact kind should, however, be obvious from context.
Array objects are mutable sequences and Str objects are immutable sequences.
Iterable
Iterable objects provide the iterator method:
Str, Range, Array, Map, Set and Stream objects are iterable.
Iterator
An object that supports the iterator interface allows iterating over the items of a composite object. It provides these methods:
- hasNext()
- Return a boolean indicating whether there are additional objects in the iteration.
- next()
- 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.