Stdlib320.ListA module containing basic list operations
length l is the number of elements in l
let _ = assert (length [1;2;3] = 3)nth l i is the ith element of l if i >= 0 and i < length l
let _ = assert (nth [1;2;3] 1 = 2)Raises a Failure exception if length l < i and an Invalid_argument exception if i < 0
Same as the previous function, but is None in the case of failure.
Combines a list of lists from left to right
let _ = assert ([concat [[1;2;3];[4;5;6];[7;8;9]] = [1;2;3;4;5;6;7;8;9]])map f l is l but with f applied to every element
let _ = assert (map abs [-1;-2;-3] = [1;2;3])filter f l is the elements of l (in order) which satisfy the predicate f
let _ = assert ([filter ((<) 5) [3;4;5;6;7] = [6;7]])Left-associative folding function for lists. fold_left op init [x_1;x_2;...;x_n] is equivalent to op (...(op (op init x_1) x_2)...) x_n
Right-associative folding function for lists. fold_right op [x_1;x_2;...;x_n] is equivalent to op x_1 (op x_2 (...(op x_n base)...))
Membership predicate for lists. mem x l is
true if x appears in lfalse otherwiseFinds based on a predicate. find f l is the first appearance of an element of l which satisfies f.
Raises a Not_found exception otherwise.
Same as the previous function, but is None in the case of failure.
Generic sorting function for lists. sort f l has the same elements as l, but sorted according to the comparing function f
Membership function for association lists. assoc x l is equivalent to
snd (find (fun (k, v) -> k = x))
Same as the previous function, but is None in the case of failure
remove_assoc k l is l but with the first appearance of a pair of the form (k, v) removed