Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Stream.ResultSourceHigher-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).
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) tGeneralization 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.tfold 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.