OCaml library : Stdlib.Either (original) (raw)
Module Stdlib.Either
module Either: [Either](Either.html)
type ('a, 'b) t =
| | Left of 'a |
---|---|
| | Right of 'b |
A value of ('a, 'b) Either.t
contains either a value of 'a
or a value of 'b
val left : 'a -> ('a, 'b) [t](Either.html#TYPEt)
val right : 'b -> ('a, 'b) [t](Either.html#TYPEt)
val is_left : ('a, 'b) [t](Either.html#TYPEt) -> bool
is_left (Left v)
is true
, is_left (Right v)
is false
.
val is_right : ('a, 'b) [t](Either.html#TYPEt) -> bool
is_right (Left v)
is false
, is_right (Right v)
is true
.
val find_left : ('a, 'b) [t](Either.html#TYPEt) -> 'a option
find_left (Left v)
is Some v
, find_left (Right _)
is None
val find_right : ('a, 'b) [t](Either.html#TYPEt) -> 'b option
find_right (Right v)
is Some v
, find_right (Left _)
is None
val map_left : ('a1 -> 'a2) -> ('a1, 'b) [t](Either.html#TYPEt) -> ('a2, 'b) [t](Either.html#TYPEt)
map_left f e
is Left (f v)
if e
is Left v
and e
if e
is Right _
.
val map_right : ('b1 -> 'b2) -> ('a, 'b1) [t](Either.html#TYPEt) -> ('a, 'b2) [t](Either.html#TYPEt)
map_right f e
is Right (f v)
if e
is Right v
and e
if e
is Left _
.
val map : left:('a1 -> 'a2) -> right:('b1 -> 'b2) -> ('a1, 'b1) [t](Either.html#TYPEt) -> ('a2, 'b2) [t](Either.html#TYPEt)
map ~left ~right (Left v)
is Left (left v)
,map ~left ~right (Right v)
is Right (right v)
.
val fold : left:('a -> 'c) -> right:('b -> 'c) -> ('a, 'b) [t](Either.html#TYPEt) -> 'c
fold ~left ~right (Left v)
is left v
, andfold ~left ~right (Right v)
is right v
.
val iter : left:('a -> unit) -> right:('b -> unit) -> ('a, 'b) [t](Either.html#TYPEt) -> unit
iter ~left ~right (Left v)
is left v
, anditer ~left ~right (Right v)
is right v
.
val for_all : left:('a -> bool) -> right:('b -> bool) -> ('a, 'b) [t](Either.html#TYPEt) -> bool
for_all ~left ~right (Left v)
is left v
, andfor_all ~left ~right (Right v)
is right v
.
val equal : left:('a -> 'a -> bool) -> right:('b -> 'b -> bool) -> ('a, 'b) [t](Either.html#TYPEt) -> ('a, 'b) [t](Either.html#TYPEt) -> bool
equal ~left ~right e0 e1
tests equality of e0
and e1
using left
and right
to respectively compare values wrapped by Left _
andRight _
.
val compare : left:('a -> 'a -> int) -> right:('b -> 'b -> int) -> ('a, 'b) [t](Either.html#TYPEt) -> ('a, 'b) [t](Either.html#TYPEt) -> int
compare ~left ~right e0 e1
totally orders e0
and e1
using left
andright
to respectively compare values wrapped by Left _
and Right _
.Left _
values are smaller than Right _
values.