Module Stdlib.ResultSource
Result values.
Result values handle computation results and errors in an explicit and declarative manner without resorting to exceptions.
Results
The type for result values. Either a value Ok v or an error Error e.
ok v is Ok v.
error e is Error e.
value r ~default is v if r is Ok v and default otherwise.
get_ok r is v if r is Ok v and raise otherwise.
get_ok' is like get_ok but in case of error uses the error message for raising Invalid_argument.
get_error r is e if r is Error e and raise otherwise.
error_to_failure r is v if r is Ok v and raises Failure e if r is Error e.
bind r f is f v if r is Ok v and r if r is Error _.
join rr is r if rr is Ok r and rr if rr is Error _.
map f r is Ok (f v) if r is Ok v and r if r is Error _.
product r0 r1 is Ok (v0, v1) if r0 is Ok v0 and r1 is Ok v2 and otherwise returns the error of r0, if any, or the error of r1.
map_error f r is Error (f e) if r is Error e and r if r is Ok _.
fold ~ok ~error r is ok v if r is Ok v and error e if r is Error e.
retract r is v if r is Ok v or Error v.
iter f r is f v if r is Ok v and () otherwise.
iter_error f r is f e if r is Error e and () otherwise.
Predicates and comparisons
is_ok r is true if and only if r is Ok _.
is_error r is true if and only if r is Error _.
val equal :
ok:('a -> 'a -> bool) ->
error:('e -> 'e -> bool) ->
('a, 'e) Stdlib.result ->
('a, 'e) Stdlib.result ->
boolequal ~ok ~error r0 r1 tests equality of r0 and r1 using ok and error to respectively compare values wrapped by Ok _ and Error _.
val compare :
ok:('a -> 'a -> int) ->
error:('e -> 'e -> int) ->
('a, 'e) Stdlib.result ->
('a, 'e) Stdlib.result ->
intcompare ~ok ~error r0 r1 totally orders r0 and r1 using ok and error to respectively compare values wrapped by Ok _ and Error _. Ok _ values are smaller than Error _ values.
Converting
to_option r is r as an option, mapping Ok v to Some v and Error _ to None.
to_list r is [v] if r is Ok v and [] otherwise.
to_seq r is r as a sequence. Ok v is the singleton sequence containing v and Error _ is the empty sequence.