Version: 0.19.0

List

let length: nat

Get the number of elements in a list.

let size: nat

Get the number of elements in a list.

Synonym for List.length.

let head_opt : (list: list<'a>) => option<'a>

Get the head of a list

let tail_opt : (list: list<'a>) => option<list<'a>>

Get the tail of a list

let iter: (iterator: ((item: 'a) => unit), list: list<'a>) => unit

Iterate over items in a list.

let iter_op = (l: list<int>): unit => {
let predicate = (i: int): unit => assert(i > 3);
List.iter(predicate, l);
};
let map: (mapper: ((item: 'a) => 'b), list: list<'a>) => list<'b>

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

let larger_list: list<int> = list([1, 2, 3]);
let increment = (i : int): int => i + 1;
// Creates a new list with all elements incremented by 1
let plus_one : list<int> = List.map(increment, larger_list);
let fold: ((folder: [accumulator: 'accumulator, item: 'item]) => 'accumulator, list: list<'item>, accumulator: 'accumulator) => 'accumulator

Fold over items in a list;

let my_list: list<int> = list([1, 2, 3]);
let sum = ([result, i]: [int, int]): int => result + i;
let sum_of_elements: int = List.fold(sum, my_list, 0);
let fold_left: (((a: ['accumulator, 'item]) => 'accumulator), 'accumulator, list<'item>) => 'accumulator

Fold over items in a list;

let my_list : list<int> = list([1, 2, 3]);
let sum = ([result, i]: [int, int]): int => result + i;
let sum_of_elements : int = List.fold_left (sum, 0, my_list);
let fold_right: (((a: ['item, 'accumulator]) => 'accumulator), list<'item>, 'accumulator) => 'accumulator

Fold over items in a list;

let my_list : list<int> = list([1, 2, 3]);
let sum_right = ([i, result]: [int, int]): int => result + i;
let sum_of_elements : int = List.fold_right (sum_right, my_list, 0);