Flicker

fractioneater.github.io

List Class


Subtype of Sequence

Static Methods

List() -> List

Creates a new empty list.

List.filled(size: Integer, value: Object) -> List

Creates a new list with size elements, each initialized to value.

Operators

.* (count: Integer) -> List

Returns a list made by repeating the initial one count times.

.+ (other: Sequence) -> List

Returns a list made by adding other to the end of this one.

Properties / Attributes

.size or .count -> Integer

The number of elements in the list.

Methods

.add(value: Object) -> None

Adds value to the end of list.

.addAll(seq: Sequence) -> None

Adds all elements of seq to the end of the list.

.clear() -> None

Remove all items from this list.

.filter(rule: |arg: Object| -> Object) -> List

Creates a new list with only the items from the original that rule returns a truthy value for. Order of elements will stay the same.

This method uses eager evaluation, so if you want a lazy alternative use lazyFilter.

.get(index: Integer) or this[index] -> Object

Returns item index of the list.

.set(index: Integer, value: Object) or this[index] = value -> Object

Sets item index of this list to value, and returns value.

.indexOf(value: Object) -> Integer, None

Returns the index of the first occurrence of value, or None if value is not in the list.

.insert(index: Integer, value: Object) -> Object

Inserts value into item index of the list, and returns value.

var l = [1, 2, 4, 5]  # [1, 2, 4, 5]
l.insert(2, 3)        # [1, 2, 3, 4, 5]
.iterate(iterator: Object) and .iteratorValue(iterator: Object) -> Object

Iterates over the values in the list, starting from index 0.

.map(transformation: |arg: Object| -> Object) -> List

Returns a list created by mapping all elements, in order, with transformation.

This method has eager evaluation; use lazyMap for a lazy version.

.partition(low: Integer, high: Integer, comparer: |a: Object, b: Object| -> Object) -> Integer

Sorts through a partition of a list specified by low and high, and returns the position of the next partition.

Used internally by quicksort.

.quicksort(low: Integer, high: Integer, comparer: |a: Object, b: Object| -> Object) -> None

Runs partition to sort through a partition of a list, and recursively calls itself to eventually sort the whole list.

Used internally by sort() and sort(1).

.remove(value: Object) -> Object, None

Removes the first occurrence of value from the list and returns it. Returns None if value is not found.

.removeAt(index: Integer) -> Object

Removes the element at index from the list, and returns it.

.sort() -> None

Sorts this list from least to greatest, using quicksort.

.sort(comparer: |a: Object, b: Object| -> Object)

Sorts this list using comparer to compare values. A wrapper around quicksort.

var l = [1, 5, 7, 3, 6]   # [1, 5, 7, 3, 6]
l.sort { |a, b| a >= b }  # [7, 6, 5, 3, 1]
.sum() -> Integer

Returns the sum of all elements in the list. A wrapper around Sequence.reduce.

.swap(index1: Integer, index2: Integer) -> None

Switches the values at index index1 and index2.

.toString() -> String

Joins the elements of this list into a comma-separated string with [ and ] delimiters.