package tezos-lwt-result-stdlib

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
include Bare_sigs.Seq.S

Common interface with Stdlib

include module type of Seq with type 'a t = 'a Seq.t and type 'a node = 'a Seq.node
type 'a t = 'a Seq.t

The type of delayed lists containing elements of type 'a. Note that the concrete list node 'a node is delayed under a closure, not a lazy block, which means it might be recomputed every time we access it.

and 'a node = 'a Seq.node =
  1. | Nil
  2. | Cons of 'a * 'a t

A fully-evaluated list node, either empty or containing an element and a delayed tail.

val empty : 'a t

The empty sequence, containing no elements.

val return : 'a -> 'a t

The singleton sequence containing only the given element.

val cons : 'a -> 'a t -> 'a t

cons x xs is the sequence containing the element x followed by the sequence xs

  • since 4.11
val append : 'a t -> 'a t -> 'a t

append xs ys is the sequence xs followed by the sequence ys

  • since 4.11
val map : ('a -> 'b) -> 'a t -> 'b t

map f seq returns a new sequence whose elements are the elements of seq, transformed by f. This transformation is lazy, it only applies when the result is traversed.

If seq = [1;2;3], then map f seq = [f 1; f 2; f 3].

val filter : ('a -> bool) -> 'a t -> 'a t

Remove from the sequence the elements that do not satisfy the given predicate. This transformation is lazy, it only applies when the result is traversed.

val filter_map : ('a -> 'b option) -> 'a t -> 'b t

Apply the function to every element; if f x = None then x is dropped; if f x = Some y then y is returned. This transformation is lazy, it only applies when the result is traversed.

val flat_map : ('a -> 'b t) -> 'a t -> 'b t

Map each element to a subsequence, then return each element of this sub-sequence in turn. This transformation is lazy, it only applies when the result is traversed.

val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a

Traverse the sequence from left to right, combining each element with the accumulator using the given function. The traversal happens immediately and will not terminate on infinite sequences.

Also see List.fold_left

val iter : ('a -> unit) -> 'a t -> unit

Iterate on the sequence, calling the (imperative) function on every element. The traversal happens immediately and will not terminate on infinite sequences.

val unfold : ('b -> ('a * 'b) option) -> 'b -> 'a t

Build a sequence from a step function and an initial value. unfold f u returns empty if f u returns None, or fun () -> Cons (x, unfold f y) if f u returns Some (x, y).

For example, unfold (function [] -> None | h::t -> Some (h,t)) l is equivalent to List.to_seq l.

  • since 4.11

Lwtreslib-specific extensions

val first : 'a t -> 'a option

first s is None if s is empty, it is Some x where x is the first element of s otherwise.

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'.

val fold_left_e : ('a -> 'b -> ('a, 'trace) result) -> 'a -> 'b t -> ('a, 'trace) result

Similar to fold_left but wraps the traversal in result. The traversal is interrupted if one of the step returns an Error _.

val fold_left_s : ('a -> 'b -> 'a Lwt.t) -> 'a -> 'b t -> 'a Lwt.t

Similar to fold_left but wraps the traversing in Lwt. Each step of the traversal is started after the previous one has resolved. The traversal is interrupted if one of the promise is rejected.

val fold_left_es : ('a -> 'b -> ('a, 'trace) result Lwt.t) -> 'a -> 'b t -> ('a, 'trace) result Lwt.t

Similar to fold_left but wraps the traversing in result Lwt.t. Each step of the traversal is started after the previous one resolved. The traversal is interrupted if one of the step is rejected or is fulfilled with Error _.

val iter_e : ('a -> (unit, 'trace) result) -> 'a t -> (unit, 'trace) result

Similar to iter but wraps the iteration in result. The iteration is interrupted if one of the step returns an Error _.

val iter_s : ('a -> unit Lwt.t) -> 'a t -> unit Lwt.t

Similar to iter but wraps the iteration in Lwt. Each step of the iteration is started after the previous one resolved. The iteration is interrupted if one of the promise is rejected.

val iter_es : ('a -> (unit, 'trace) result Lwt.t) -> 'a t -> (unit, 'trace) result Lwt.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 _.

val iter_p : ('a -> unit Lwt.t) -> 'a t -> unit Lwt.t

Similar to iter but wraps the iteration in Lwt. All the steps of the iteration are started concurrently. 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.

Values which have made it to the Stdlib since then

This section is for forward compatibility: bringing you the features of more recent OCaml Stdlib than we compile against.

val concat : 'a t t -> 'a t

concat s is a sequence containing the elements of the elements of s.

val concat_map : ('a -> 'b t) -> 'a t -> 'b t

concat_map is an alias for flat_map

val iter_ep : ('a -> (unit, 'error Monad.trace) result Lwt.t) -> 'a t -> (unit, 'error Monad.trace) result Lwt.t

Similar to iter but wraps the iteration in result Lwt.t. All the steps of the iteration are started concurrently. 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.