package ocaml-solo5
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=47876167068345542f49279e8fd28896
sha512=272081ec51a6ed69c08e4e8fa64fee3df53fd84c66c0c07a653891c88b342cf74553e1c95711e4fbc18922c899a3448a649f3bd9858f8d89cae834ad2b67fffb
doc/stdlib/Stdlib/Either/index.html
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
find_left (Left v) is Some v, find_left (Right _) is None
find_right (Right v) is Some v, find_right (Left _) is None
map_left f e is Left (f v) if e is Left v and e if e is Right _.
map_right f e is Right (f v) if e is Right v and e if e is Left _.
map ~left ~right (Left v) is Left (left v), map ~left ~right (Right v) is Right (right v).
fold ~left ~right (Left v) is left v, and fold ~left ~right (Right v) is right v.
iter ~left ~right (Left v) is left v, and iter ~left ~right (Right v) is right v.
for_all ~left ~right (Left v) is left v, and for_all ~left ~right (Right v) is right v.