Satisfied Interfaces: Category, Cloneable<Clone>, Collection<Element>, Container, ContainerWithFirstElement<Element,Null>, Correspondence<Key,Item>, Iterable<Element>, Ranged<Index,Span>, Sized
All Known Satisfying Classes: Array, LazyList, String
All Known Satisfying Interfaces: Empty, Sequence

Represents a collection in which every element has a unique non-negative integer index.

A List is a Collection of its elements, and a Correspondence from indices to elements.

Direct access to a list element by index produces a value of optional type. The following idiom may be used instead of upfront bounds-checking, as long as the list element type is a non-null type:

value char = "hello world"[index];
if (exists char) { /*do something*/ }
else { /*out of bounds*/ }

To iterate the indexes of a List, use the following idiom:

for (i->char in "hello world".indexed) { ... }
See also: Sequence<Element>, Empty, Array<Element>
Attributes
firstSource Code
shared actual default Element? first

Returns the first element of this List, if any.

hashSource Code
shared actual default Integer hash

The hash value of the value, which allows the value to be an element of a hash-based set or key of a hash-based map. Implementations must respect the constraint that if x==y then x.hash==y.hash.

iteratorSource Code
shared actual default Iterator<Element> iterator

An iterator for the elements belonging to this container.

lastSource Code
shared actual default Element? last

Returns the last element of this List, if any.

lastIndexSource Code
shared formal Integer? lastIndex

The index of the last element of the list, or null if the list is empty.

See also: size
reversedSource Code
shared formal List<Element> reversed

Reverse this list, returning a new list.

sizeSource Code
shared actual default Integer size

The number of elements in this sequence, always sequence.lastIndex+1.

See also: lastIndex
Inherited Attributes
Attributes inherited from: Object
Attributes inherited from: Cloneable<Clone>
Attributes inherited from: Object
Attributes inherited from: Container
Attributes inherited from: ContainerWithFirstElement<Element,Null>
Attributes inherited from: Correspondence<Key,Item>
Attributes inherited from: Iterable<Element>
Attributes inherited from: Sized
Methods
definesSource Code
shared actual default Boolean defines(Integer index)

Determines if the given index refers to an element of this sequence, that is, if index<=sequence.lastIndex.

equalsSource Code
shared actual default Boolean equals(Object that)

Two Lists are considered equal iff they have the same size and entry sets. The entry set of a list l is the set of elements of l.indexed. This definition is equivalent to the more intuitive notion that two lists are equal iff they have the same size and for every index either:

  • the lists both have the element null, or
  • the lists both have a non-null element, and the two elements are equal.
findLastSource Code
shared actual default Element? findLast(Boolean selecting(Element elem))

The last element which satisfies the given predicate, if any, or null otherwise.

itemSource Code
shared formal Element? item(Integer index)

Returns the element of this sequence with the given index, or null if the given index is past the end of the sequence, that is, if index>sequence.lastIndex. The first element of the sequence has index 0.

withLeadingSource Code
shared default Sequence<Element> withLeading<Other>(Other element)

Returns a new List that starts with the specified element, followed by the elements of this List.

withTrailingSource Code
shared default Sequence<Element> withTrailing<Other>(Other element)

Returns a new List that contains the specified element appended to the end of this Lists' elements.

Inherited Methods
Methods inherited from: Category
Methods inherited from: Correspondence<Key,Item>
Methods inherited from: Iterable<Element>
Methods inherited from: Ranged<Index,Span>