Legend:
Library
Module
Module type
Parameter
Class
Class type
Library
Module
Module type
Parameter
Class
Class type
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).
type ('a, 'e) t = ('a, 'e) Core_kernel.Result.t Stream.t
val all :
('a, 'e) t ->
f:('a Stream.t -> ('b, 'e) Core_kernel.Result.t) ->
('b, 'e) Core_kernel.Result.t
val all' : ('a, 'e) t -> f:('a Stream.t -> 'b) -> ('b, 'e) Core_kernel.Result.t
val 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
map rs ~f
maps Ok
results with a total function f
val 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.
Analoguous of map2_exn
for total functions
val 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.
val fold' :
('a, 'e) t ->
init:'b ->
f:('b -> 'a -> 'b) ->
('b, 'e) Core_kernel.Result.t
Same as fold
, but for total functions.