module OLinq:sig..end
The purpose is to provide powerful combinators to express iteration, transformation and combination of collections of items.
Functions and operations are assumed to be referentially transparent, i.e. they should not rely on external side effects, they should not rely on the order of execution.
OLinq.(
of_list [1;2;3]
|> flat_map (fun x -> (x -- (x+10)))
|> count ()
|> flat_map of_pmap
|> sort ()
|> run_list
);;
- : (int * int) list = [(1, 1); (2, 2); (3, 3); (4, 3); (5, 3); (6, 3);
(7, 3); (8, 3); (9, 3); (10, 3); (11, 3); (12, 2); (13, 1)]
OLinq.(
IO.read_file "/tmp/foo"
|> IO.lines
|> sort ()
|> IO.to_file_lines "/tmp/bar"
);;
- : `Ok ()
OLinq.(
1 -- 20
|> group_by (fun x -> x mod 3)
|> run_list
) ;;
- : (int * int list) list =
[(2, [20; 17; 14; 11; 8; 5; 2]);
(0, [18; 15; 12; 9; 6; 3; 0]);
(1, [19; 16; 13; 10; 7; 4; 1])]
type'asequence =('a -> unit) -> unit
type'aequal ='a -> 'a -> bool
type'aord ='a -> 'a -> int
type'ahash ='a -> int
type'aor_error =[ `Error of string | `Ok of 'a ]
module Iterable:sig..end
type('a, 'b)map =('a, 'b) OLinq_map.t
type ('a, +[< `Any | `AtMostOne | `One ]) t
'card indicates how many elements are in the collection,
with `Any indicating the number is unknown, `AtMostOne that there
are 0 or 1 elements and `One exactly one.
Conceptually, the cardinalities are ordered from most precise (`One)
to least precise (`Any): `One < `AtMostOne < `Any.
type'at_any =('a, [ `Any ]) t
type'at_one =('a, [ `One ]) t
type'at_at_most_one =('a, [ `AtMostOne ]) t
val empty : ('a, [< `Any | `AtMostOne | `One > `AtMostOne ]) tval return : 'a -> ('a, [< `Any | `AtMostOne | `One > `One ]) tval of_list : 'a list -> ('a, [ `Any ]) tval of_array : 'a array -> ('a, [ `Any ]) t
val of_array_i : 'a array -> (int * 'a, [ `Any ]) t
val range : int -> int -> (int, [ `Any ]) trange i j goes from i up to j includedval (--) : int -> int -> (int, [ `Any ]) tOLinq.rangeval of_hashtbl : ('a, 'b) Hashtbl.t -> ('a * 'b, [ `Any ]) t
val of_seq : 'a sequence -> ('a, [ `Any ]) tval of_vec : 'a OLinq_vec.t -> ('a, [ `Any ]) t
val of_queue : 'a Queue.t -> ('a, [ `Any ]) t
val of_stack : 'a Stack.t -> ('a, [ `Any ]) t
val of_string : string -> (char, [ `Any ]) tval of_map : ('a, 'b) map -> ('a * 'b, [ `Any ]) tof_map m yields each binding of mval of_multimap : ('a, 'b list) map -> ('a * 'b, [ `Any ]) tof_multimap m yields each single binding of mval run : ?limit:int ->
('a, [< `Any | `AtMostOne | `One ]) t -> 'a Iterable.tlimit : max number of values to returnval run_list : ?limit:int -> ('a, [< `Any | `AtMostOne | `One ]) t -> 'a list
val run_array : ?limit:int -> ('a, [< `Any | `AtMostOne | `One ]) t -> 'a array
val run_vec : ?limit:int -> ('a, [< `Any | `AtMostOne | `One ]) t -> 'a OLinq_vec.t
val run1 : ('a, [ `One ]) t -> 'aval run_head : ('a, [< `Any | `AtMostOne | `One ]) t -> 'a optionval run1_exn : ('a, [< `Any | `AtMostOne | `One ]) t -> 'a
val map : ('a -> 'b) ->
('a, [< `Any | `AtMostOne | `One ] as 'c) t -> ('b, 'c) tval (>|=) : ('a, [< `Any | `AtMostOne | `One ] as 'c) t ->
('a -> 'b) -> ('b, 'c) tOLinq.mapval filter : ('a -> bool) ->
('a, [< `Any | `AtMostOne | `One ]) t -> ('a, [ `Any ]) tval size : ('a, [< `Any | `AtMostOne | `One ]) t ->
(int, [< `Any | `AtMostOne | `One > `One ]) tsize t returns one value, the number of items returned by tval choose : ('a, [< `Any | `AtMostOne | `One ]) t ->
('a, [< `Any | `AtMostOne | `One > `AtMostOne ]) tval filter_map : ('a -> 'b option) ->
('a, [< `Any | `AtMostOne | `One ]) t -> ('b, [ `Any ]) tval flat_map_seq : ('a -> 'b sequence) ->
('a, [< `Any | `AtMostOne | `One ]) t -> ('b, [ `Any ]) tOLinq.flat_map but using sequencesval flat_map_l : ('a -> 'b list) ->
('a, [< `Any | `AtMostOne | `One ]) t -> ('b, [ `Any ]) tval flatten_list : ('a list, [< `Any | `AtMostOne | `One ]) t -> ('a, [ `Any ]) t
val flatten_seq : ('a sequence, [< `Any | `AtMostOne | `One ]) t ->
('a, [ `Any ]) t
val flatten_map : (('a, 'b) map, [< `Any | `AtMostOne | `One ]) t ->
('a * 'b, [ `Any ]) t
val flatten_multimap : (('a, 'b list) map, [< `Any | `AtMostOne | `One ]) t ->
('a * 'b, [ `Any ]) t
val take : int -> ('a, [< `Any | `AtMostOne | `One ]) t -> ('a, [ `Any ]) tn elementsval take1 : ('a, [< `Any | `AtMostOne | `One ]) t ->
('a, [< `Any | `AtMostOne | `One > `AtMostOne ]) tOLinq.take that keeps only the first elementval take_while : ('a -> bool) ->
('a, [< `Any | `AtMostOne | `One ]) t -> ('a, [ `Any ]) tval sort : ?cmp:'a ord -> unit -> ('a, [ `Any ]) t -> ('a, [ `Any ]) tval sort_by : ?cmp:'b ord ->
('a -> 'b) -> ('a, [ `Any ]) t -> ('a, [ `Any ]) tsort_by proj c sorts the collection c by projecting elements using
proj, then using cmp to order themval distinct : ?cmp:'a ord -> unit -> ('a, [ `Any ]) t -> ('a, [ `Any ]) tval group_by : ?cmp:'b ord ->
?eq:'b equal ->
?hash:'b hash ->
('a -> 'b) -> ('a, [ `Any ]) t -> ('b * 'a list, [ `Any ]) tgroup_by f takes a collection c as input, and returns a collection
of pairs k, l where every element x of l satifies f x = k.
In other words, elements of the collection that have the same
image by f are grouped in the same list.val group_by_reflect : ?cmp:'b ord ->
?eq:'b equal ->
?hash:'b hash ->
('a -> 'b) ->
('a, [ `Any ]) t ->
(('b, 'a list) map, [< `Any | `AtMostOne | `One > `One ]) tgroup_by_reflect f takes a collection c as input, and returns
a multimap m such that for each x in c, x occurs in m under the
key f x.
In other words, f is used
to obtain a key from x, and x is added to the multimap using this key.val count : ?cmp:'a ord ->
?eq:'a equal ->
?hash:'a hash ->
unit -> ('a, [ `Any ]) t -> ('a * int, [ `Any ]) tcount c counts how many times each element of the collection
occur, and returns pairs of x, count(x)val count_reflect : ?cmp:'a ord ->
?eq:'a equal ->
?hash:'a hash ->
unit ->
('a, [ `Any ]) t ->
(('a, int) map, [< `Any | `AtMostOne | `One > `One ]) tcount_reflect c returns a map from elements of c to the number
of time those elements occur.val fold : ('b -> 'a -> 'b) ->
'b ->
('a, [< `Any | `AtMostOne | `One ]) t ->
('b, [< `Any | `AtMostOne | `One > `One ]) tval is_empty : ('a, [< `Any | `AtMostOne ]) t ->
(bool, [< `Any | `AtMostOne | `One > `One ]) t
val sum : (int, [< `Any | `AtMostOne ]) t ->
(int, [< `Any | `AtMostOne | `One > `One ]) t
val contains : ?eq:'a equal ->
'a ->
('a, [< `Any | `AtMostOne | `One ]) t ->
(bool, [< `Any | `AtMostOne | `One > `One ]) tcontains x q returns true if x is among the elements returned
by q. Careful, this runs q and might be slow!val average : (int, [< `Any | `AtMostOne | `One ]) t ->
(int, [< `Any | `AtMostOne | `One > `One ]) t
val max : (int, [< `Any | `AtMostOne | `One ]) t ->
(int, [< `Any | `AtMostOne | `One > `One ]) t
val min : (int, [< `Any | `AtMostOne | `One ]) t ->
(int, [< `Any | `AtMostOne | `One > `One ]) t
val for_all : ('a -> bool) ->
('a, [< `Any | `AtMostOne | `One ]) t ->
(bool, [< `Any | `AtMostOne | `One > `One ]) t
val exists : ('a -> bool) ->
('a, [< `Any | `AtMostOne | `One ]) t ->
(bool, [< `Any | `AtMostOne | `One > `One ]) t
val find : ('a -> bool) ->
('a, [< `Any | `AtMostOne | `One ]) t ->
('a option, [< `Any | `AtMostOne | `One > `One ]) t
val find_map : ('a -> 'b option) ->
('a, [< `Any | `AtMostOne | `One ]) t ->
('b option, [< `Any | `AtMostOne | `One > `One ]) tval join : ?cmp:'key ord ->
?eq:'key equal ->
?hash:'key hash ->
('a -> 'key) ->
('b -> 'key) ->
merge:('key -> 'a -> 'b -> 'c option) ->
('a, [< `Any | `AtMostOne | `One ]) t ->
('b, [< `Any | `AtMostOne | `One ]) t -> ('c, [ `Any ]) tjoin key1 key2 ~merge is a binary operation
that takes two collections a and b, projects their
elements resp. with key1 and key2, and combine
values (x,y) from (a,b) with the same key
using merge. If merge returns None, the combination
of values is discarded.val group_join : ?cmp:'a ord ->
?eq:'a equal ->
?hash:'a hash ->
('b -> 'a) ->
('a, [< `Any | `AtMostOne | `One ]) t ->
('b, [< `Any | `AtMostOne | `One ]) t ->
('a * 'b list, [ `Any ]) tgroup_join key2 associates to every element x of
the first collection, all the elements y of the second
collection such that eq x (key y). Elements of the first
collections without corresponding values in the second one
are mapped to []val group_join_reflect : ?cmp:'a ord ->
?eq:'a equal ->
?hash:'a hash ->
('b -> 'a) ->
('a, [< `Any | `AtMostOne | `One ]) t ->
('b, [< `Any | `AtMostOne | `One ]) t ->
(('a, 'b list) map, [< `Any | `AtMostOne | `One > `One ]) tOLinq.group_join, but reflects the groups as a multimapval product : ('a, [< `Any | `AtMostOne | `One ]) t ->
('b, [< `Any | `AtMostOne | `One ]) t -> ('a * 'b, [ `Any ]) tval append : ('a, [< `Any | `AtMostOne | `One ]) t ->
('a, [< `Any | `AtMostOne | `One ]) t -> ('a, [ `Any ]) tval inter : ?cmp:'a ord ->
?eq:'a equal ->
?hash:'a hash ->
('a, [< `Any | `AtMostOne | `One ]) t ->
('a, [< `Any | `AtMostOne | `One ]) t -> ('a, [ `Any ]) tval union : ?cmp:'a ord ->
?eq:'a equal ->
?hash:'a hash ->
('a, [< `Any | `AtMostOne | `One ]) t ->
('a, [< `Any | `AtMostOne | `One ]) t -> ('a, [ `Any ]) tval diff : ?cmp:'a ord ->
?eq:'a equal ->
?hash:'a hash ->
('a, [< `Any | `AtMostOne | `One ]) t ->
('a, [< `Any | `AtMostOne | `One ]) t -> ('a, [ `Any ]) tval subset : ?cmp:'a ord ->
?eq:'a equal ->
?hash:'a hash ->
('a, [< `Any | `AtMostOne | `One ]) t ->
('a, [< `Any | `AtMostOne | `One ]) t -> (bool, [ `One ]) tsubset () a b returns true if all elements of a belong to bval map_fst : ('a -> 'b) ->
('a * 'c, [< `Any | `AtMostOne | `One ] as 'd) t ->
('b * 'c, 'd) t
val map_snd : ('a -> 'b) ->
('c * 'a, [< `Any | `AtMostOne | `One ] as 'd) t ->
('c * 'b, 'd) t
val flatten_opt : ('a option, [< `Any | `AtMostOne | `One ]) t -> ('a, [ `Any ]) tNone and mapping Some x to x.val pure : 'a -> ('a, [< `Any | `AtMostOne | `One ]) tOLinq.returnval app : ('a -> 'b, [< `Any | `AtMostOne | `One ] as 'c) t ->
('a, 'c) t -> ('b, 'c) tval (<*>) : ('a -> 'b, [< `Any | `AtMostOne | `One ] as 'c) t ->
('a, 'c) t -> ('b, 'c) tOLinq.app
Careful, those operators do not allow any optimization before running the
query, they might therefore be pretty slow.
val flat_map : ('a -> ('b, [< `Any | `AtMostOne | `One ]) t) ->
('a, [< `Any | `AtMostOne | `One ]) t -> ('b, [ `Any ]) tval (>>=) : ('a, [< `Any | `AtMostOne | `One ]) t ->
('a -> ('b, [< `Any | `AtMostOne | `One ]) t) -> ('b, [ `Any ]) tOLinq.flat_mapval lazy_ : ('a lazy_t, [< `Any | `AtMostOne | `One ] as 'b) t -> ('a, 'b) t
exception UnwrapNone
val opt_unwrap_exn : ('a option, [< `Any | `AtMostOne | `One ] as 'b) t -> ('a, 'b) tUnwrapNone if some option is Nonemodule Infix:sig..end
val reflect_vec : ('a, [< `Any | `AtMostOne | `One ]) t ->
('a OLinq_vec.t, [< `Any | `AtMostOne | `One > `One ]) treflect_seq q evaluates all values in q and returns a sequence
of all those values. Also blocks optimizationsval reflect_list : ('a, [< `Any | `AtMostOne | `One ]) t ->
('a list, [< `Any | `AtMostOne | `One > `One ]) treflect_list q evaluates all values in q and returns a list
of all those values. Also blocks optimizationsval reflect_hashtbl : ('a * 'b, [< `Any | `AtMostOne | `One ]) t ->
(('a, 'b) Hashtbl.t, [< `Any | `AtMostOne | `One > `One ]) tval reflect_queue : ('a, [< `Any | `AtMostOne | `One ]) t ->
('a Queue.t, [< `Any | `AtMostOne | `One > `One ]) t
val reflect_stack : ('a, [< `Any | `AtMostOne | `One ]) t ->
('a Stack.t, [< `Any | `AtMostOne | `One > `One ]) t
module AdaptSet:
module AdaptMap:
module IO:sig..end