Lists
Lists are zero-terminated, nested row 2-tuples. They are declared by prepending a ~ to what looks like row syntax, like this: ~[] (in the REPL we have to wrap this in parentheses):
NIL
(NIL)
> NILEvaluates to 0.
NIL == 0 ; the empty listCONS
(CONS x xs)
> x : a
> xs : List a
> List aConstructs a new list by adding an element to the front of an existing list.
CONS 1 NIL == [1 0] ; a list with one element
CONS b#a (CONS b#b NIL) == [b#a [b#a 0]] ; a list with two elements
CONS 1 (CONS 2 (CONS 3 NIL)) == [1 [2 [3 0]]] ; a list with three elementslistCase
(listCase xs d k)
> xs : List a
> d : a
> k : a
> aPattern matches on a list, providing cases for empty and non-empty lists.
listSing
Creates a singleton list containing one element.
listMap
Applies a function to every element of a list.
listForEach
Alias for listMap. Applies a function to every element of a list.
listHead
Returns the first element of a list.
listSafeHead
Returns the first element of a list, or a fallback value if the list is empty.
listUnsafeHead
Returns the first element of a list, otherwise 0. Unsafe if the list is empty.
listUnsafeTail
Returns the tail of a list (all elements except the first). Unsafe if the list is empty.
listIdxCps
Continuation-passing style function to get the element at a given index in a list.
listIdxOr
Returns the element at a given index in a list, or a fallback value if the index is out of bounds.
listIdx
Returns the element at a given index in a list, or 0 if the index is out of bounds.
listLastOr
Returns the last element of a list, or a fallback value if the list is empty.
listUnsafeLast
Returns the last element of a list. Unsafe if the list is empty.
listLast
Returns the last element of a list.
listFoldl
Left-associative fold of a list.
listFoldl1
Left-associative fold of a non-empty list, using the first element as the initial accumulator.
listFoldr
Right-associative fold of a list.
listLen
Computes the length of a list.
listToRow
Converts a list to a row.
sizedListToRow
Converts a list to a row of a specified size, padding with zeros if necessary.
sizedListToRowRev
Converts a list to a row of a specified size in reverse order, padding with zeros if necessary.
listToRowRev
Converts a list to a row in reverse order.
listFromRow
Converts a row to a list.
listAnd
Returns TRUE if all elements in the list are TRUE, otherwise FALSE.
listOr
Returns TRUE if any element in the list is TRUE, otherwise FALSE.
listSum
Computes the sum of all elements in a list of numbers.
listAll
Returns TRUE if all elements in the list satisfy the given predicate.
listAllEql
Returns TRUE if all elements in the list are equal.
listAny
Returns TRUE if any element in the list satisfies the given predicate.
listHas
Checks if a list contains a specific element.
listEnumFrom
Creates an infinite list of consecutive integers starting from a given number.
listWeld
Concatenates two lists.
listCat
Concatenates a list of lists into a single list.
listCatMap
Applies a function to all elements in a list and concatenates the results.
listTake
Takes the first n elements from a list.
listDrop
Drops the first n elements from a list.
listTakeWhile
Takes elements from the front of a list while they satisfy a predicate.
listDropWhile
Drops elements from the front of a list while they satisfy a predicate.
listZipWith
Combines two lists element-wise using a given function.
listZip
Combines two lists into a list of pairs.
listFilter
Keeps only the elements of a list that satisfy a predicate.
listIsEmpty
Checks if a list is empty.
listMinimumOn
Finds the minimum element in a list based on a comparison function.
listSortOn
Sorts a list based on a key function.
listNub
Removes duplicate elements from a list, keeping only the first occurrence.
listIterate
Generates an infinite list by repeatedly applying a function to an initial value.
listGen
Generates a list of n elements using a given function.
listRep
Generates a list of n copies of a given element.
listFindIndex
Finds the index of the first element in a list that satisfies a predicate. If there is none, the third argument is returned. If there is one, then its index is passed as an argument to the fourth argument.
listElemIndex
Finds the index of the first occurrence of an element in a list.
listIsPrefixOf
Checks if one list is a prefix of another list.
​​​​​listSearch
Searches for all occurrences of a list satisfying a predicate and returns their indices and the remaining lists.
listSubstringSearch
Searches for all occurrences of a substring in a list and returns their indices and the remaining lists.
listIndexed
Pairs each element in a list with its index.
listIntersperse
Intersperses an element between every element of a list.
listRev
Reverses a list.
listSnoc
Adds an element to the end of a list.
listProd
Computes the Cartesian product of two lists.
Last updated