Sequence that calls the given function to produce elements. The sequence may be transient (depending on the function), and definitely is infinite. You may want to use take and persistent.
Cycle forever through the given sequence. Assume the given sequence can be traversed any amount of times (not transient). This yields an infinite sequence, you should use something like take not to loop forever.
val foldi : f:('a->int ->'b->'a)->init:'a->'bt->'a
Fold over elements of the sequence and their index, consuming it
val fold_map : f:('acc->'a->'acc * 'b)->init:'acc->'at->'bt
fold_map f acc l is like map, but it carries some state as in fold. The state is not returned, it is just used to thread some information to the map function.
since 0.9
val fold_filter_map :
f:('acc->'a->'acc * 'b option)->init:'acc->'at->'bt
fold_filter_map f acc l is a fold_map-like function, but the function can choose to skip an element by retuning None.
Iterate on the sequence, storing elements in an efficient internal structure.. The resulting sequence can be iterated on as many times as needed. Note: calling persistent on an already persistent sequence will still make a new copy of the sequence!
Lazy version of persistent. When calling persistent_lazy s, a new sequence s' is immediately returned (without actually consuming s) in constant time; the first time s' is iterated on, it also consumes s and caches its content into a inner data structure that will back s' for future iterations.
warning: on the first traversal of s', if the traversal is interrupted prematurely (take, etc.) then s' will not be memorized, and the next call to s' will traverse s again.
Cartesian product of the sequences. When calling product a b, the caller MUST ensure that b can be traversed as many times as required (several times), possibly by calling persistent on it beforehand.
val join : join_row:('a->'b->'c option)->'at->'bt->'ct
join ~join_row a b combines every element of a with every element of b using join_row. If join_row returns None, then the two elements do not combine. Assume that b allows for multiple iterations.
Take elements while they satisfy the predicate, then stops iterating. Will work on an infinite sequence s if the predicate is false for at least one element of s.
val fold_while :
f:('a->'b->'a * [ `Stop | `Continue ])->init:'a->'bt->'a
Folds over elements of the sequence, stopping early if the accumulator returns ('a, `Stop)
Reverse the sequence. O(n) memory and time, needs the sequence to be finite. The result is persistent and does not depend on the input being repeatable.
Convert the sequence into a list. Preserves order of elements. This function is tail-recursive, but consumes 2*n memory. If order doesn't matter to you, consider to_rev_list.
Iterates on characters of the input (can block when one iterates over the sequence). If you need to iterate several times on this sequence, use persistent.
Iterator on decreasing integers in stop...start by steps -1. See (--^) for an infix version
val int_range_by : step:int ->start:int ->stop:int ->int t
int_range_by ~step ~start:i ~stop:j is the range starting at i, including j, where the difference between successive elements is step. use a negative step for a decreasing sequence.
Pretty print a sequence of 'a, using the given pretty printer to print each elements. An optional separator string can be provided.
val pp_buf :
?sep:string ->(Buffer.t->'a-> unit)->Buffer.t->'at->
unit
Print into a buffer
val to_string : ?sep:string ->('a-> string)->'at-> string
Print into a string
Basic IO
Very basic interface to manipulate files as sequence of chunks/lines. The sequences take care of opening and closing files properly; every time one iterates over a sequence, the file is opened/closed again.
Example: copy a file "a" into file "b", removing blank lines: