List
List Operators
range from to
Generates a list of all numbers between from
(inclusive) and to
(exclusive). List elements can be integer or float types.
Equivalent to the (..)
binary operator.
Example:
rangei from to
Returns a list of all numbers between from
(inclusive) and to
(inclusive). List elements can be integer or float types.
Equivalent to the (..=)
binary operator.
Example:
concat x y
Returns a list of length 2 containing x
as the first element and y
as the second element. x
and y
must be of the same type.
Equivalent to the (++)
binary operator.
Example:
prepend value list
Return a new list with value
added to the start of list
. value
must be the same type as the elements of list
.
Equivalent to the (+>)
binary operator.
Example:
append list value
Return a new list with value
added to the end of list
. value
must be the same type as the elements of list
.
Equivalent to the (<+)
binary operator.
Example:
Query Functions
nth index list
Returns the element at index
of list
. index
must be of the integer type.
Example:
length list
Returns the number of elements in list
.
Example:
is_empty list
Returns true if length of list
is zero, false otherwise.
Example:
contains value list
Returns true if value
is equal to an element in list
, false otherwise.
Example:
index_of value list
Returns the index of first element in list
that is equal to value
, -1 if not found.
Example:
Modification Functions
set index value list
Returns a new list where element of list
at index
is replaced with value
. index
must be of the integer type and value
must be the same type as elements of list
.
Example:
head list
Returns the first element of list
.
Example:
tail list
Returns a new list containing all elements of list
except the first one.
Example:
init list
Returns a new list containing all elements of list
except the last one.
Example:
last list
Returns the last element of list
.
Example:
take count list
Returns a new list containing the first count
elements of list
, or the last elements if count
is negative. count
must be of the integer type.
Example:
drop count list
Returns a new list excluding the first count
elements of list
, or the last elements if count
is negative. count
must be of the integer type.
Example:
slice start end list
Returns a new list containing elements from list
between the start
and end
indices. start
and end
must be of the integer type.
Example:
split index list
Divides list
into two parts at index
, returning a two-dimensional list containing the two resulting sublists. index
must be of the integer type.
Example:
Transformation Functions
reverse list
Returns a new list with the elements of list
in reverse order.
Example:
unique list
Returns a new list containing only the distinct elements of list
, removing duplicates.
Example:
sort list
Returns a new list with the elements of list
sorted in ascending order.
Example:
flatten list
Returns a new list by concatenating all nested lists within list
into a single, one-dimensional list.
Example:
intersperse value list
Returns a new list with a specified value inserted between each element of list
. value
must be of the same type of the elements of list
.
Example:
Reduction Functions
min_of list
Returns the smallest element of list
. Elements of list
must be of the integer or float types.
Example:
max_of list
Returns the largest element of list
. Elements of list
must be of the integer or float types.
Example:
sum list
Returns the total sum of all elements in list
. Elements of list
must be of the integer, float, or complex types.
Example:
product list
Returns the total product of all elements in list
. Elements of list
must be of the integer, float, or complex types.
Example:
Last updated