package cfstream

  1. Overview
  2. Docs

Module Stream.ResultSource

Higher-order functions for streams of results

The functions in this module can be used to iterate on a stream of results with a function that only considers the non-error case. The iterated function thus doesn't need to do the pattern match on each Result value.

For each kind of iteration, two versions are proposed. One for total functions (that is, functions that cannot fail), the other for partial functions (they are assumed to return a Result in this case).

Sourcetype ('a, 'e) t = ('a, 'e) Core_kernel.Result.t Stream.t
Sourceval all : ('a, 'e) t -> f:('a Stream.t -> ('b, 'e) Core_kernel.Result.t) -> ('b, 'e) Core_kernel.Result.t
Sourceval all' : ('a, 'e) t -> f:('a Stream.t -> 'b) -> ('b, 'e) Core_kernel.Result.t
Sourceval to_exn : ('a, 'e) t -> error_to_exn:('e -> exn) -> 'a Stream.t
Sourceval map : ('a, 'e) t -> f:('a -> ('b, 'e) Core_kernel.Result.t) -> ('b, 'e) t

map' rs ~f maps Ok results with a partial function f

Sourceval map' : ('a, 'e) t -> f:('a -> 'b) -> ('b, 'e) t

map rs ~f maps Ok results with a total function f

Sourceval map2_exn : ('a, 'e) t -> ('b, 'e) t -> f:('a -> 'b -> ('c, 'e) Core_kernel.Result.t) -> ('c, 'e) t

Generalization of map with two streams of results. If the two streams fail simultaneously, one of the two errors is propagated.

Sourceval map2_exn' : ('a, 'e) t -> ('b, 'e) t -> f:('a -> 'b -> 'c) -> ('c, 'e) t

Analoguous of map2_exn for total functions

Sourceval fold : ('a, 'e) t -> init:'b -> f:('b -> 'a -> ('b, 'e) Core_kernel.Result.t) -> ('b, 'e) Core_kernel.Result.t

fold rs ~init ~f computes a value by iterating f on each Ok element of rs starting from init. The computation stops with an Error case as soon as one is met on the stream, or when f returns one.

Sourceval fold' : ('a, 'e) t -> init:'b -> f:('b -> 'a -> 'b) -> ('b, 'e) Core_kernel.Result.t

Same as fold, but for total functions.

OCaml

Innovation. Community. Security.