![]() | ![]() | ![]() |
|
List module provides basic operations of lists. list type, with Nil and Cons constructors is defined in Core module.
typedef <'a>list <'a>t; | |
Type of lists holding elements of type 'a. See Core::list for definition. |
int length(<'a>t l); | |
Return number of elements in l. It takes linear time. |
void iter(*(void ('a)) f, <'a>t l); | |
Run f on each elements of l, starting from head. |
<'b>t map(*('b ('a)) f, <'a>t l); | |
Run f on each element of l and return list composed of what it returns. |
<'a>t concat(<'a>t x, <'a>t y); | |
Return list being concatenation of x and y. It takes O(length(x)) time. |
<'a>t filter(*(bool ('a)) f, <'a>t l); | |
Return list of elements of l, for which f returns true. |
bool exists(*(bool ('a)) f, <'a>t l); | |
Return true iff there exists such x in l, that f(x) == true. |
'a fold_left(*('a ('a, 'b)) f, 'a init, <'b>t l); | |
If l is [e1, e2, e3, ..., en], then return f(...f(f(init, e1), e2), ..., en), i.e. execute f(init, e1), result pass to f(result, e2) etc. Return final result. |
<'a>t qsort(*(int ('a, 'a)) cmp, <'a>t l); | |
Return l sorted according to comparison function cmp. cmp should satisfy x == y <=> cmp(x, y) == 0, x < y <=> cmp(x, y) < 0. Mediana selection is rather stupid (first element of list), so this might take up to O(length(l)^2) time. |
<'a>t rev(<'a>t l); | |
Return l reversed. |
'a find(*(bool ('a)) f, <'a>t l); | |
Return first element x of l, for which f(x) == true. If there is no such x, then raise Not_found. |
<'a>t nil(); | |
Return Nil. |
<'a>t cons('a a, <'a>t b); | |
Return Cons(a, b). |
<'a>t cons1('a d1); | |
Return [d1]. |
<'a>t cons2('a d1, 'a d2); | |
Return [d1, d2]. |
<'a>t cons3('a d1, 'a d2, 'a d3); | |
Return [d1, d2, d3]. |
<'a>t cons4('a d1, 'a d2, 'a d3, 'a d4); | |
Return [d1, d2, d3, d4]. |
void iter2(*(void ('a, 'b)) f, <'a>t a, <'b>t b); | |
Iterate f over a and b. Raise Invalid_argument if lists have different length. |
<'a>t map2(*('a ('b, 'c)) f, <'b>t a, <'c>t b); | |
Iterate f over a and b. Raise Invalid_argument if lists have different length. Return list composed of what f returns. |