# [Ride v5] List functions
⚠️ This is the documentation for the Standard Library version 5, which is currently available for Stagenet only. Go to Mainnet version
Name | Description | Complexity |
---|---|---|
cons | Inserts element to the beginning of the list | 1 |
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.
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.
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.
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.
removeByIndex(list: List[T], index: Int): List[T]
# Parameters
Parameter | Description |
---|---|
list : List[T] | List |
index : T | Index of the element |
# Examlpes
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