Support.EitherAd hoc disjoint unions of two types.
include module type of Stdlib.Eitherval left : 'a -> ('a, 'b) tval right : 'b -> ('a, 'b) tval is_left : ('a, 'b) t -> boolval is_right : ('a, 'b) t -> boolval find_left : ('a, 'b) t -> 'a optionval find_right : ('a, 'b) t -> 'b optionval fold : left:('a -> 'c) -> right:('b -> 'c) -> ('a, 'b) t -> 'cval iter : left:('a -> unit) -> right:('b -> unit) -> ('a, 'b) t -> unitval for_all : left:('a -> bool) -> right:('b -> bool) -> ('a, 'b) t -> boolval eliminate : ('e -> 'c) -> ('a -> 'c) -> ('e, 'a) t -> 'cEliminator for disjoint unions.
Transforms both sides of the union.
Promotes a function that constructs a union into a function that transforms a union.
Either.bind and Either.right witness that Either.t is a monad if the left-hand type is fixed.
val forget : ('e, 'a) t -> 'a optionEliminates the union into a Stdlib.option, forgetting the value in the left-hand side.
val of_option : 'a option -> (unit, 'a) tConverts a Stdlib.option into a union with a unit left-hand side.
val of_option' : (unit -> 'e) -> 'a option -> ('e, 'a) tConverts a Stdlib.option into a union with a left-hand side constructed from a thunk in case the Stdlib.option contained Option.t.None.
val to_option : ('e, 'a) t -> 'a optionConverts a union into an option, forgetting the left side, if any.
Infix form of Either.bind.
Infix form of Either.map_right.
val trap : (unit -> 'a) -> (exn, 'a) tTraps exceptions thrown by evaluating a function into a union. You can delay handling the exceptions until the union is eliminated by using the following trick. Suppose e : (exn, a) t. Then,
eliminate
(fun ex ->
try raise ex with
| Whatever -> do_something_to_handle_Whatever)
(fun x -> success x)The benefit of using trap is that you can be selective about which code gets its exceptions caught.