Version: 0.3.0

List

function length : nat

Get the number of elements in a list.

function size : nat

Get the number of elements in a list.

Synonym for List.length.

function iter : ('a -> unit) -> list('a) -> unit

Iterate over items in a list.

function iter_op (const l : list (int)) : unit is
block {
function iterated (const i : int) : unit is
if i > 3 then Unit else (failwith ("Below range.") : unit)
} with List.iter (iterated, l)

Note that list_iter is deprecated.

Alternatively it's also possible to use loops.

function map : ('a -> 'b) -> list('a) -> list('b)

Apply a function to items of a list to create a new list.

const larger_list: list(int) = list [1; 2; 3]
function increment (const i : int): int is i + 1
// Creates a new list with all elements incremented by 1
const plus_one : list (int) = List.map (increment, larger_list)

Note that list_map is deprecated.

function fold : (('accumulator -> 'item -> 'accumulator) -> list('item) -> 'accumulator) -> 'accumulator

Fold over items in a list;

const my_list: list(int) = list [1; 2; 3]
function sum (const acc : int; const i : int): int is acc + i
const sum_of_elements : int = List.fold (sum, my_list, 0)

Note that list_fold is deprecated.