# List functions
| Name | Description | Complexity |
|---|---|---|
| cons(A, List[B]): List[A|B] | Inserts element to the beginning of the list | 1 |
| containsElement(List[T], T): Boolean | Check if the element is in the list | 5 |
| getElement(List[T], Int): T | Gets the element from the list | 2 |
| indexOf(List[T], T): Int|Unit | Returns the index of the first occurrence of the element in the list | 5 |
| lastIndexOf(List[T], T): Int|Unit | Returns the index of the last occurrence of the element in the list | 5 |
| max(List[Int]): Int | Returns the largest element in the list of integers | 3 |
| max(List[BigInt]): BigInt | Returns the largest element in the list of big integers | 6 for Standard library version 8 192 for Standard library version 7 or 6 |
| min(List[Int]): Int | Returns the smallest element in the list of integers | 3 |
| min(List[BigInt]): BigInt | Returns the smallest element in the list of big integers | 6 for Standard library version 8 192 for Standard library version 7 or 6 |
| removeByIndex(List[T], Int): List[T] | Removes an element from the list at a given index | 4 for Standard library version 8 7 for Standard library version 7 or 6 |
| replaceByIndex(List[T], Int, T): List[T] | Replaces an element in the list at a given index | 4 |
| size(List[T]): Int | Returns the size of the list | 2 |
A, B, T means any valid type.
# cons(A, List[B]): List[A|B]
Inserts element to the beginning of the list.
cons(head:T, tail: List[T]): List[T]
# Parameters
| Parameter | Description |
|---|---|
head: T | Element |
tail: List[T] | List |
# Examples
cons("Ride", ["on", "Waves"]) # Returns ["Ride", "on", "Waves"]
cons(1, [2, 3, 4, 5]) # Returns [1, 2, 3, 4, 5]
# containsElement(List[T], T): Boolean
Check if the element is in the list.
containsElement(list: List[T], element: T): Boolean
# Parameters
| Parameter | Description |
|---|---|
list: List[T] | List |
element: T | Element to search for |
# getElement(List[T], Int): T
Gets the element from the list by index. getElement(arr, i) is equivalent to arr[i].
getElement(arr: List[T], pos: Int): T
# Parameters
| Parameter | Description |
|---|---|
arr: List[T] | List |
pos: Int | Index of the element |
# Examples
getElement(["Ride", "on", "Waves"], 0) # Returns "Ride"
getElement([false, true], 1) # Returns true
# indexOf(List[T], T): Int|Unit
Returns the index of the first occurrence of the element in the list or unit if the element is missing.
indexOf(list: List[T], element: T): Int|Unit
# Parameters
| Parameter | Description |
|---|---|
list: List[T] | List |
element: T | Element to locate |
# Example
let stringList = ["a","b","a","c"]
indexOf("a", stringList) # Returns 0
# lastIndexOf(List[T], T): Int|Unit
Returns the index of the last occurrence of the element in the list or unit if the element is missing.
lastIndexOf(list: List[T], element: T): Int|Unit
# Parameters
| Parameter | Description |
|---|---|
list: List[T] | List |
element: T | Element to locate |
# Example
let stringList = ["a","b","a","c"]
lastIndexOf("a", stringList) # Returns 2
# max(List[Int]): Int
Returns the largest element in the list of integers. Fails if the list is empty.
max(List[Int]): Int
# Parameters
| Parameter | Description |
|---|---|
list: List[Int] | List |
# max(List[BigInt]): BigInt
Returns the largest element in the list of big integers. Fails if the list is empty.
max(List[BigInt]): BigInt
# Parameters
| Parameter | Description |
|---|---|
list: List[BigInt] | List |
# min(List[Int]): Int
Returns the smallest element in the list of integers. Fails if the list is empty.
min(List[Int]): Int
# Parameters
| Parameter | Description |
|---|---|
list: List[Int] | List |
# min(List[BigInt]): BigInt
Returns the smallest element in the list of big integers. Fails if the list is empty.
min(List[BigInt]): BigInt
# Parameters
| Parameter | Description |
|---|---|
list: List[BigInt] | List |
# removeByIndex(List[T], Int): List[T]
Removes an element from the list at a given index and returns the new list.
removeByIndex(list: List[T], index: Int): List[T]
# Parameters
| Parameter | Description |
|---|---|
list: List[T] | List |
index: Int | Index of the element |
# Example
removeByIndex(["Waves", 42, true], 1) # Returns ["Waves", true]
# replaceByIndex(List[T], Int, T): List[T]
Replaces an element in the list at a given index and returns the new list. The type of the element's new value must match the type of list elements.
⚠️ The functions is added in Standard library version 8.
replaceByIndex(list: List[T], index: Int, value: T): List[T]
# Parameters
| Parameter | Description |
|---|---|
list: List[T] | List |
index: Int | Index of the element |
value: T | New value |
# Example
replaceByIndex(["Waves", 42, true], 1, "Ride") # Returns ["Waves", "Ride", true]
# size(List[T]): Int
Returns the size of the list.
size(arr: List[T]): Int
# Parameters
| Parameter | Description |
|---|---|
arr: List[T] | List |
# Examples
size(["Ride", "on", "Waves"]) # Returns 3