Satisfied Interfaces: Category, Cloneable<List<Element>>, Collection<Element>, Correspondence<Integer,Element>, Iterable<Element,Null>, Ranged<Integer,List<Element>>
Direct Known Satisfying Classes: Array<Element>, LazyList<Element>, String
Direct Known Satisfying Interfaces: Sequential<Element>

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, Empty, Array
Attributes
firstSource Code
shared actual default Element? first

Returns the first element of this List, if any.

Refined declaration: first
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.

Refined declaration: hash
lastSource Code
shared actual default Element? last

Returns the last element of this List, if any.

Refined declaration: last
lastIndexSource Code

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

See also: List.size
restSource Code
shared formal List<Element> rest

The rest of the list, without the first element.

Refined declaration: rest
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: List.lastIndex
Refined declaration: size
Inherited Attributes
Attributes inherited from: Object
Attributes inherited from: Cloneable<Clone>
Attributes inherited from: Collection<Element>
Attributes inherited from: Correspondence<Key,Item>
Attributes inherited from: Iterable<Element,Absent>
Methods
containsSource Code
shared actual default Boolean contains(Object element)

Determines if this list contains the given value. Equivalent to occurs().

See also: occurs
Refined declaration: contains
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`.
Refined declaration: defines
endsWithSource Code
shared default Boolean endsWith(List<Anything> sublist)

Determine if the given list occurs at the end of this list.

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.
Refined declaration: equals
findLastSource Code
shared actual default Element? findLast(Boolean selecting(Element elem))

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

Refined declaration: findLast
firstInclusionSource Code

The first index in this list at which the given list occurs.

firstOccurrenceSource Code
shared default Integer? firstOccurrence(Anything element)

The first index in this list at which the given element occurs.

getSource Code

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`.
Refined declaration: get
includesSource Code
shared default Boolean includes(List<Anything> sublist)

Determine if the given list occurs at some index in this list.

includesAtSource Code
shared default Boolean includesAt(Integer index, List<Anything> sublist)

Determine if the given list occurs at the given index of this list.

Parameters:
  • index

    The index at which this list might occur

inclusionsSource Code

The indexes in this list at which the given list occurs.

indexesSource Code

The indexes in this list for which the element satisfies the given predicate.

Parameters:
  • selecting

    The predicate the indexed elements must satisfy

initialSource Code
shared default List<Element> initial(Integer length)

Select the first elements of this list, returning a list no longer than the given length. If this list is shorter than the given length, return this list. Otherwise return a list of the given length.

See also: List.terminal
iteratorSource Code
shared actual default Iterator<Element> iterator()

An iterator for the elements belonging to this container.

Refined declaration: iterator
lastInclusionSource Code

The last index in this list at which the given list occurs.

lastOccurrenceSource Code
shared default Integer? lastOccurrence(Anything element)

The last index in this list at which the given element occurs.

longerThanSource Code
shared actual default Boolean longerThan(Integer length)

Determines if this iterable object has more elements than the given length. This is an efficient operation for iterable objects with many elements.

Refined declaration: longerThan
occurrencesSource Code

The indexes in this list at which the given element occurs.

occursSource Code
shared default Boolean occurs(Anything element)

Determines if the given value occurs as an element in this list.

occursAtSource Code
shared default Boolean occursAt(Integer index, Anything element)

Determines if the given value occurs at the given index in this list.

shorterThanSource Code
shared actual default Boolean shorterThan(Integer length)

Determines if this iterable object has fewer elements than the given length. This is an efficient operation for iterable objects with many elements.

Refined declaration: shorterThan
startsWithSource Code
shared default Boolean startsWith(List<Anything> sublist)

Determine if the given list occurs at the start of this list.

terminalSource Code
shared default List<Element> terminal(Integer length)

Select the last elements of the list, returning a list no longer than the given length. If this list is shorter than the given length, return this list. Otherwise return a list of the given length.

See also: List.initial
trimSource Code
shared default List<Element> trim(Boolean trimming(Element elem))

Trim the elements satisfying the given predicate function from the start and end of this list, returning a list no longer than this list.

trimLeadingSource Code
shared default List<Element> trimLeading(Boolean trimming(Element elem))

Trim the elements satisfying the given predicate function from the start of this list, returning a list no longer than this list.

trimTrailingSource Code
shared default List<Element> trimTrailing(Boolean trimming(Element elem))

Trim the elements satisfying the given predicate function from the end of this list, returning a list no longer than this list.

withLeadingSource Code
shared default [<Element|Other>+] withLeading<Other>(Other element)

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

Parameters:
  • element

    The first element of the resulting sequence.

See also: following
withTrailingSource Code
shared default [<Element|Other>+] withTrailing<Other>(Other element)

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

Parameters:
  • element

    The last element of the resulting sequence.

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