Module Stdlib.EitherSource
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) -> 'a list -> 'b list * 'c listIf 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.
A value of ('a, 'b) Either.t contains either a value of 'a or a value of 'b
val left :
('a : value_or_null) ('b : value_or_null). 'a ->
('a, 'b) Stdlib.Either.t @@ portableleft v is Left v.
val right :
('a : value_or_null) ('b : value_or_null). 'b ->
('a, 'b) Stdlib.Either.t @@ portableright v is Right v.
val is_left :
('a : value_or_null) ('b : value_or_null). ('a, 'b) Stdlib.Either.t ->
bool @@ portableis_left (Left v) is true, is_left (Right v) is false.
val is_right :
('a : value_or_null) ('b : value_or_null). ('a, 'b) Stdlib.Either.t ->
bool @@ portableis_right (Left v) is false, is_right (Right v) is true.
val find_left :
('a : value_or_null) ('b : value_or_null). ('a, 'b) Stdlib.Either.t ->
'a option @@ portablefind_left (Left v) is Some v, find_left (Right _) is None
val find_right :
('a : value_or_null) ('b : value_or_null). ('a, 'b) Stdlib.Either.t ->
'b option @@ portablefind_right (Right v) is Some v, find_right (Left _) is None
val map_left :
('a1 : value_or_null) ('a2 : value_or_null) ('b : value_or_null). ('a1 ->
'a2) ->
('a1, 'b) Stdlib.Either.t ->
('a2, 'b) Stdlib.Either.t @@ portablemap_left f e is Left (f v) if e is Left v and e if e is Right _.
val map_right :
('a : value_or_null) ('b1 : value_or_null) ('b2 : value_or_null). ('b1 ->
'b2) ->
('a, 'b1) Stdlib.Either.t ->
('a, 'b2) Stdlib.Either.t @@ portablemap_right f e is Right (f v) if e is Right v and e if e is Left _.
val map :
('a1 : value_or_null) ('a2 : value_or_null) ('b1 : value_or_null) ('b2 : value_or_null).
left:
('a1 -> 'a2) ->
right:('b1 -> 'b2) ->
('a1, 'b1) Stdlib.Either.t ->
('a2, 'b2) Stdlib.Either.t @@ portablemap ~left ~right (Left v) is Left (left v), map ~left ~right (Right v) is Right (right v).
val fold :
('a : value_or_null) ('b : value_or_null) ('c : value_or_null). left:
('a -> 'c) ->
right:('b -> 'c) ->
('a, 'b) Stdlib.Either.t ->
'c @@ portablefold ~left ~right (Left v) is left v, and fold ~left ~right (Right v) is right v.
val iter :
('a : value_or_null) ('b : value_or_null). left:('a -> unit) ->
right:('b -> unit) ->
('a, 'b) Stdlib.Either.t ->
unit @@ portableiter ~left ~right (Left v) is left v, and iter ~left ~right (Right v) is right v.
val for_all :
('a : value_or_null) ('b : value_or_null). left:('a -> bool) ->
right:('b -> bool) ->
('a, 'b) Stdlib.Either.t ->
bool @@ portablefor_all ~left ~right (Left v) is left v, and for_all ~left ~right (Right v) is right v.
val equal :
('a : value_or_null) ('b : value_or_null). left:('a -> 'a -> bool) ->
right:('b -> 'b -> bool) ->
('a, 'b) Stdlib.Either.t ->
('a, 'b) Stdlib.Either.t ->
bool @@ portableequal ~left ~right e0 e1 tests equality of e0 and e1 using left and right to respectively compare values wrapped by Left _ and Right _.
val compare :
('a : value_or_null) ('b : value_or_null). left:('a -> 'a -> int) ->
right:('b -> 'b -> int) ->
('a, 'b) Stdlib.Either.t ->
('a, 'b) Stdlib.Either.t ->
int @@ portablecompare ~left ~right e0 e1 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.