Module Either
: sigend
Either type.
Either is the simplest and most generic sum/variant type: a value of ('a,'b)Either.t is either a Left(v:'a) or a Right(v:'b) .
It is a natural choice in the API of generic functions where values could fall in two different cases,
possibly at different types, without assigning a specific meaning to what each case should be.
For example:
List.partition_map:('a->('b,'c)Either.t)->'alist->'blist*'clist
If you are looking for a parametrized type where one alternative means success and the other means
failure, you should use the more specific type Result.t .
Since 4.12
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 'bvalleft : 'a->('a,'b)tleftv is Leftv .
valright : 'b->('a,'b)trightv is Rightv .
valis_left : ('a,'b)t->boolis_left(Leftv) is true , is_left(Rightv) is false .
valis_right : ('a,'b)t->boolis_right(Leftv) is false , is_right(Rightv) is true .
valfind_left : ('a,'b)t->'aoptionfind_left(Leftv) is Somev , find_left(Right_) is Nonevalfind_right : ('a,'b)t->'boptionfind_right(Rightv) is Somev , find_right(Left_) is Nonevalmap_left : ('a1->'a2)->('a1,'b)t->('a2,'b)tmap_leftfe is Left(fv) if e is Leftv and e if e is Right_ .
valmap_right : ('b1->'b2)->('a,'b1)t->('a,'b2)tmap_rightfe is Right(fv) if e is Rightv and e if e is Left_ .
valmap : left:('a1->'a2)->right:('b1->'b2)->('a1,'b1)t->('a2,'b2)tmap~left~right(Leftv) is Left(leftv) , map~left~right(Rightv) is Right(rightv) .
valfold : left:('a->'c)->right:('b->'c)->('a,'b)t->'cfold~left~right(Leftv) is leftv , and fold~left~right(Rightv) is rightv .
valiter : left:('a->unit)->right:('b->unit)->('a,'b)t->unititer~left~right(Leftv) is leftv , and iter~left~right(Rightv) is rightv .
valfor_all : left:('a->bool)->right:('b->bool)->('a,'b)t->boolfor_all~left~right(Leftv) is leftv , and for_all~left~right(Rightv) is rightv .
valequal : left:('a->'a->bool)->right:('b->'b->bool)->('a,'b)t->('a,'b)t->boolequal~left~righte0e1 tests equality of e0 and e1 using left and right to respectively compare values
wrapped by Left_ and Right_ .
valcompare : left:('a->'a->int)->right:('b->'b->int)->('a,'b)t->('a,'b)t->intcompare~left~righte0e1 totally orders e0 and e1 using left and right to respectively compare values
wrapped by Left_ and Right_ . Left_ values are smaller than Right_ values.
OCamldoc 2025-06-12 Either(3o)