Monads.ResultMonadAn implementation of a monad "design pattern" for handling errors across functions, using the Result type.
return ?map_ok x wraps the value x in an Ok result. If map_ok is provided, it applies the function f to x before wrapping it.
fail ?map_error e wraps the value e in an Error result. If map_error is provided, it applies the function f to e before wrapping it in Error.
bind m f applies the function f to the value inside m if m is Ok, otherwise returns the same Error value. Note: This function doesn't accumulate errors.
( >>= ) m f is an infix operator for bind.
( let* ) m f is a syntactic sugar for bind in monadic let binding.
apply m f applies the function f to the value inside m if m is Ok, and wraps the result in Ok.
( >>| ) m f is an infix operator for apply.
( let+ ) m f is a syntactic sugar for apply in monadic let binding.
bind_error m f applies the function f to the value inside m if m is Error, otherwise returns the Ok value.
( >>! ) m f is an infix operator for bind_error.
fold_left f acc l is a monadic fold left over the list l with the function f, threading an accumulator of type result.
val fold_left2 :
('a -> 'b -> 'c -> ('a, 'd) Stdlib.result) ->
'a ->
'b list ->
'c list ->
('a, 'd) Stdlib.resultfold_left2 f acc l1 l2 folds the lists l1 and l2 from the left with the function f, threading an accumulator of type result.
fold_right f acc l folds the list l from the right with the function f, threading an accumulator of type result.
val fold_right2 :
('a -> 'b -> 'c -> ('a, 'd) Stdlib.result) ->
'a ->
'b list ->
'c list ->
('a, 'd) Stdlib.resultfold_right2 f acc l1 l2 folds the lists l1 and l2 from the right with the function f, threading an accumulator of type result.
map f l maps the function f over the list l, returning a result of type result.
filter_map f l maps the function f over the list l, filtering out None values, and returning a result of type result.
iter f l applies the function f to each element of the list l, returning a result of type result wrapping unit value.
partition f l partitions the list l into two lists based on the predicate f, returning a result of type result.