Class List
The List class represents a container of a given type, written as List[<inner type>]. A List value can be accessed through a positive index or a negative one (with negative indexes being an offset from the end). Attempting to access an invalid index will produce IndexError.
0 define accumulate(output: List[B], fn: Function(List[B], A)): List[B]
Build a transformed List with a predicate.
This calls fn for each element in self, with output as the first argument each time. Unlike map, fn does not have to return a value for every element in self.
This method is for situations where elements in a source dataset do not map 1 to 1 with the result dataset.
0 define all(fn: Function(A => Boolean)): Boolean
This calls fn for each element within self.
Returns true if fn returns true for all elements given, or if self is empty.
Otherwise, this returns false.
0 define any(fn: Function(A => Boolean)): Boolean
This calls fn for each element within self.
Returns true if fn returns true for any element in self, or if self is empty.
Otherwise, this returns false.
0 define clear
Removes all elements present within self. No error is raised if self is being iterated over.
0 define contains(value: A): Boolean
Searches linearly through self for value. Returns true if it is found, and false otherwise.
0 define count(fn: Function(A => Boolean)): Integer
This calls fn for each element within self. The result of this function is the number of times that fn returns true.
0 define delete_at(index: Integer)
Attempts to remove index from the List. If index is negative, then it is considered an offset from the end of the List.
IndexErrorifindexis out of range.
0 define each(fn: Function(A)): List[A]
Calls fn for each element within self. The result of this function is self, so that this method can be chained with others.
0 define each_index(fn: Function(Integer)): List[A]
Calls fn for each element within self. Rather than receive the elements of self, fn instead receives the index of each element.
0 define each_with_index(fn: Function(A, Integer)): List[A]
Iterate over elements with indexes.
Calls fn for each element within self. fn is given the elements as well as their indexes.
0 static define fill(count: Integer, fn: Function(Integer => A)): List[A]
Generate a List of 'count' items using 'fn'.
This calls 'fn' with an index that starts at 0 and proceeds until 'count', and does not include 'count'.
If 'count' is 0 or negative, then the resulting List will be empty.
0 define fold(start: B, fn: Function(B, A => B)): B
This calls fn for each element present within self. The first value sent to fn is initially start, but will later be the result of fn. Therefore, the value as it accumulates can be found in the first value sent to fn.
The result of this function is the result of doing an accumulation on each element within self.
0 define get(index: Integer): Option[A]
Attempt to find index within self.
If the index is within self, then the value is returned within a Some.
Otherwise, this returns None.
0 define insert(index: Integer, value: A): List[A]
Attempt to insert value at index within self. If index is negative, then it is treated as an offset from the end of self.
IndexErrorifindexis not withinself.
0 define join(separator: *String): String
Create a String consisting of the elements of self interleaved with separator.
The elements of self are converted into String values in the same way that ++ stringifies values.
If self is empty, the result is an empty String.
0 define map(fn: Function(A => B)): List[B]
This calls fn on each element within self. The result of this function is a newly-made List containing the results of fn.
0 define map_with_index(fn: Function(A, Integer => B)): List[B]
Map elements with indexes.
This is equivalent to map, except that fn receives indexes as well.
0 define merge(others: List[A]...): List[A]
Create a new List containing every element in self and others.
0 define pop: A
0 define push(value: A): List[A]
Add value to the end of self.
0 define reject(fn: Function(A => Boolean)): List[A]
This calls fn for each element within self. The result is a newly- made List holding each element where fn returns false.
0 static define repeat(count: Integer, value: A): List[A]
This creates a new List that contains value repeated count times.
ValueErrorifcountis less than 1.
0 define reverse: List[A]
Return a new List that contains all elements within self ordered from last to first.
0 define select(fn: Function(A => Boolean)): List[A]
This calls fn for each element within self. The result is a newly- made List holding each element where fn returns true.
0 define shift: A
This attempts to remove the last element from self and return it.
ValueErrorifselfis empty.
0 define size: Integer
Returns the number of elements that are within self.
0 define slice(start: *Integer, stop: *Integer): List[A]
Create a new List copying a section of self from start to stop.
If a negative index is given, it is treated as an offset from the end of self, with -1 being considered the last element.
On error, this generates an empty List. Error conditions are:
- Either
startorstopis out of range. - The
startis larger than thestop(reversed).
0 define sort(fn: *Function(A, A => Integer)): List[A]
Returns a new List that contains all elements within self in ascending order.
If fn is not provided, the elements will be compared automatically. This is only possible when the inner type is Double, Integer, or String - the first two of those will be sorted from smallest to largest, and the latter will be sorted alphabetically.
If fn is provided, it will be used to compare elements instead. It is passed two elements at a time, and its return value determines how they should be ordered:
< 0: The first element should be placed before the second one.0: The order of the elements doesn't matter (eg. they are equal).> 0: The second element should be placed before the first one.
It is expected that fn is a valid comparator, if it is provided. An invalid comparator will likely result in the returned List being identical to self, though that behavior should not be depended on.
ValueErroriffnis not provided, butselfhas an inner type that is notDouble,Integer, orString.
0 define unshift(value: A): List[A]
Inserts value at the front of self, moving all other elements to the right.
0 define zip(others: List[$1]...): List[Tuple[A, $1]]
This creates a List that contains a merger of the values within each of the elements in 'others' and 'self'.
The $1 type is a special type that allows this method to work with any number of List values.
If 'self' is List[Integer] and 'others' is List[String] and List[Double], then the resulting type is List[Tuple[Integer, String, Double]].
The size of the result List is the same as the smallest List provided.