Module Res

type 'a res = ('a, Stdlib.Format.formatter -> unit) Stdlib.result

A result for some computation. Ok or Error of Format.formatter

The following functions have been taken from (future) 4.09 Stdlib.Result. * These 5 functions, ok, error, bind, join and map should be removed * after the Stdlib upgrade.

val ok : 'a -> ('a, 'e) Stdlib.result

ok v is Ok v.

val error : 'e -> ('a, 'e) Stdlib.result

error e is Error e.

val bind : ('a, 'e) Stdlib.result -> ('a -> ('b, 'e) Stdlib.result) -> ('b, 'e) Stdlib.result

bind r f is f v if r is Ok v and r if r is Error _.

val join : (('a, 'e) Stdlib.result, 'e) Stdlib.result -> ('a, 'e) Stdlib.result

join rr is r if rr is Ok r and rr if rr is Error _.

val map : ('a -> 'b) -> ('a, 'e) Stdlib.result -> ('b, 'e) Stdlib.result

map f r is Ok (f v) if r is Ok v and r if r is Error _.

val (>>=) : ('a, 'e) Stdlib.result -> ('a -> ('b, 'e) Stdlib.result) -> ('b, 'e) Stdlib.result

Infix version of bind

val (>>) : ('a, 'e) Stdlib.result -> ('c, 'e) Stdlib.result -> ('c, 'e) Stdlib.result

Disregards the output of the first computation

val seq : ('a, 'e) Stdlib.result list -> ('a list, 'e) Stdlib.result

sequences a list of result into a result of list * basically errors out on first error or returns the whole value list

val seq_chain : ('a -> 'b -> ('a, 'e) Stdlib.result) -> 'a -> 'b list -> ('a, 'e) Stdlib.result

Chains the output of the head computation into the following tail computation while folding

val foldM : ('a -> 'b -> 'a) -> 'a -> ('b list, 'e) Stdlib.result -> ('a, 'e) Stdlib.result

Folds a list under a result type

val seqM : ('a -> 'b -> 'a) -> 'a -> ('b, 'e) Stdlib.result list -> ('a, 'e) Stdlib.result

general case of seq_

val seq_ : (unit, 'e) Stdlib.result list -> (unit, 'e) Stdlib.result

sequences a list of unit into a result of unit * errors out on first error or returns a unit

val ifM : (bool, 'e) Stdlib.result -> ('a, 'e) Stdlib.result -> ('a, 'e) Stdlib.result -> ('a, 'e) Stdlib.result

This is an if .. then .. else lifted in monadic world

val guard_with : (bool, 'e) Stdlib.result -> (unit, 'e) Stdlib.result -> (unit, 'e) Stdlib.result

converts a monadic boolean condition into a guard

val safe_unwrap : 'a -> ('a, 'e) Stdlib.result -> 'a

Unwrap the result value and return the default value if it is an error

val unwrap : 'a res -> 'a

Unwraps a result.

val map_res : ('a -> 'b) -> ('c -> 'd) -> ('a, 'c) Stdlib.result -> ('b, 'd) Stdlib.result

Maps functions to Ok or Err.

val map_err : ('a -> 'b) -> ('c, 'a) Stdlib.result -> ('c, 'b) Stdlib.result

Maps a function to a result if it's Err.

val chain : ?fmt:((Stdlib.Format.formatter -> unit) -> Stdlib.Format.formatter -> unit) -> ('a -> 'b res) -> 'a res -> 'b res

Feeds a result to a function returning a result, propagates if argument's an error.

val l_fold : ?fmt:((Stdlib.Format.formatter -> unit) -> Stdlib.Format.formatter -> unit) -> ('acc -> 'a -> 'acc res) -> 'acc -> 'a list -> 'acc res

Fold over a list of results.

val l_map : ?fmt:((Stdlib.Format.formatter -> unit) -> Stdlib.Format.formatter -> unit) -> ('a -> 'b res) -> 'a list -> 'b list res

Map over a list with a result-producing function.

val l_iter : ?fmt:((Stdlib.Format.formatter -> unit) -> Stdlib.Format.formatter -> unit) -> ('a -> unit res) -> 'a list -> unit res

Iterate over a list with a result-producing function.