# [Ride v4 and v3] List functions
⚠️ This is the documentation for the Standard library version 4 and 3. We recommend to use version 6. Go to version 6
| Name | Description | Complexity |
|---|---|---|
| cons | Inserts element to the beginning of the list | 2 for Standard Library version 3 1 for Standard Library version 4 |
| containsElement | Check if the element is in the list | 5 |
| getElement | Gets the element from the list | 2 |
| indexOf | Returns the index of the first occurrence of the element in the list | 5 |
| lastIndexOf | Returns the index of the last occurrence of the element in the list | 5 |
| max | Returns the largest element in the list | 3 |
| min | Returns the smallest item in the list | 3 |
| removeByIndex | Removes an element from the list by index | 7 |
| size | Returns the size of the list | 2 |
T means any valid type.
# cons
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
Check if the element is in the list.
⚠️ The
containsElementfunction is added in Standard library version 4.
containsElement(list: List[T], element: T): Boolean
# Parameters
| Parameter | Description |
|---|---|
list: List[T] | List |
element: T | Element to search for |
# getElement
Gets the element from the list by index.
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
Returns the index of the first occurrence of the element in the list or unit if the element is missing.
⚠️ The
indexOffunction is added in Standard library version 4.
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
Returns the index of the last occurrence of the element in the list or unit if the element is missing.
⚠️ The
lastIndexOffunction is added in Standard library version 4.
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
Returns the largest element in the list. If the list is empty, returns error.
max(List[Int]): Int
# Parameters
| Parameter | Description |
|---|---|
list: List[T] | List |
# min
Returns the smallest element in the list. If the list is empty, returns error.
min(List[Int]): Int
# Parameters
| Parameter | Description |
|---|---|
list: List[T] | List |
# removeByIndex
Removes an element from the list by index.
⚠️ The
removeByIndexfunction is added in Standard library version 4.
removeByIndex(list: List[T], index: Int): List[T]
# Parameters
| Parameter | Description |
|---|---|
list: List[T] | List |
index: T | Index of the element |
# Example
removeByIndex(["Waves", 42, true], 1) # Returns ["Waves", true]
# size
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