Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file seq_s.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2021 Nomadic Labs <contact@nomadic-labs.com> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)(** The [S] signature is similar to {!Seq.S} except that suspended nodes are
wrapped in a promise.
This allows some additional traversors ([map_s], etc.) to be applied lazily.
The functions [of_seq] and [of_seq_s] allow conversion from vanilla
sequences. *)moduletypeS=sig(** This is similar to [S.t] but the suspended node is a promise. *)type+'anode=Nil|Consof'a*'atand'at=unit->'anodeLwt.t(** [empty] is a sequence with no elements. *)valempty:'at(** [return x] is a sequence with the single element [x]. *)valreturn:'a->'at(** [return_s p] is a sequence with the value the promise [p] resolves to as
its single element. *)valreturn_s:'aLwt.t->'at(** [cons x s] is the sequence containing [x] followed by [s]. It is a whole
sequence if [s] is. *)valcons:'a->'at->'at(** [cons_s p s] is the sequence containing the value the promise [p] resolves
to, followed by [s]. *)valcons_s:'aLwt.t->'at->'at(** [append s1 s2] is a sequence [s] containing the elements of [s1] followed
by the elements of [s2]. *)valappend:'at->'at->'at(** [first s] resolves to [None] if [s] is empty (and its suspended node
resolves), it resolves to [Some x] where [x] is the first element of [s],
it does not resolve if the promised node of [s] doesn't.
Note that [first] forces the first element of the sequence, which can have
side-effects or be computationally expensive. Consider, e.g., the case
where [s = filter (fun …) s']: [first s] can force multiple of the values
from [s']. *)valfirst:'at->'aoptionLwt.t(** Similar to {!fold_left} but applies to Lwt-suspended sequences. Because
the nodes are suspended in promises, traversing may yield and,
consequently, the function [fold_left] returns a promise. *)valfold_left:('a->'b->'a)->'a->'bt->'aLwt.t(** Similar to {!fold_left} but wraps the traversal in {!result}. The
traversal is interrupted if one of the step returns an [Error _]. *)valfold_left_e:('a->'b->('a,'trace)result)->'a->'bt->('a,'trace)resultLwt.t(** Similar to {!fold_left} but the folder is within Lwt. *)valfold_left_s:('a->'b->'aLwt.t)->'a->'bt->'aLwt.t(** Similar to {!fold_left} but the folder is within result-Lwt. Traversal is
interrupted if one of the step resolves to an [Error _]. *)valfold_left_es:('a->'b->('a,'trace)resultLwt.t)->'a->'bt->('a,'trace)resultLwt.t(** [iter f s] applies [f] to each element of [s]. *)valiter:('a->unit)->'at->unitLwt.t(** Similar to {!iter} but wraps the iteration in {!result}. The iteration
is interrupted if one of the steps returns an [Error _]. *)valiter_e:('a->(unit,'trace)result)->'at->(unit,'trace)resultLwt.t(** Similar to {!iter} but wraps the iteration in {!Lwt}. Each step
of the iteration is started after the previous one is resolved. *)valiter_s:('a->unitLwt.t)->'at->unitLwt.t(** Similar to {!iter} but wraps the iteration in [result Lwt.t]. Each step
of the iteration is started after the previous one resolved. The iteration
is interrupted if one of the promise is rejected of fulfilled with an
[Error _]. *)valiter_es:('a->(unit,'trace)resultLwt.t)->'at->(unit,'trace)resultLwt.t(** Similar to {!iter} but wraps the iteration in [result Lwt.t]. The
steps of the iteration are started concurrently: one iteration starts
as soon as a node becomes resolved. The promise [iter_ep]
resolves once all the promises of the traversal resolve. At this point it
either:
- is rejected if at least one of the promises is, otherwise
- is fulfilled with [Error _] if at least one of the promises is,
otherwise
- is fulfilled with [Ok ()] if all the promises are. *)valiter_ep:('a->(unit,'trace)resultLwt.t)->'at->(unit,'tracelist)resultLwt.t(** Similar to {!iter} but wraps the iteration in {!Lwt}. The
steps of the iteration are started concurrently: one iteration is started
as soon as the node becomes resolved. The promise [iter_p f s]
is resolved only once all the promises of the iteration are. At this point
it is either fulfilled if all promises are, or rejected if at least one of
them is. *)valiter_p:('a->unitLwt.t)->'at->unitLwt.tvalmap:('a->'b)->'at->'btvalmap_s:('a->'bLwt.t)->'at->'btvalfilter:('a->bool)->'at->'at(** Similar to {!filter} but wraps the transformation in {!Lwt.t}. Each
test of the predicate is done sequentially, only starting once the
previous one has resolved. *)valfilter_s:('a->boolLwt.t)->'at->'atvalfilter_map:('a->'boption)->'at->'bt(** Similar to {!filter_map} but within [Lwt.t]. Not lazy and not
tail-recursive. *)valfilter_map_s:('a->'boptionLwt.t)->'at->'btvalunfold:('b->('a*'b)option)->'b->'atvalunfold_s:('b->('a*'b)optionLwt.t)->'b->'atvalof_seq:'aStdlib.Seq.t->'atvalof_seq_s:'aLwt.tStdlib.Seq.t->'atend