package tezos-lwt-result-stdlib
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=296bb5674bc6050afe6330326fbdd0dfc2255d414bfd6b79cc7666ac6b39316d
sha512=c061cd300a9410300851158d77bf8e56ca3c568b0b1161b38305e5b2efdcd9c746d391f832fdb2826f9a1d6babce10a9b764a4b04f5df42699f7314b9863123a
doc/bare_structs/Bare_structs/Option/index.html
Module Bare_structs.Option
Source
include Bare_sigs.Option.S
either
picks the first Some _
value of its arguments if any. More formally, either (Some x) _
is Some x
, either None (Some y)
is Some y
, and either None None
is None
.
val merge_e :
('a -> 'a -> ('a, 'e) Stdlib.result) ->
'a option ->
'a option ->
('a option, 'e) Stdlib.result
val merge_es :
('a -> 'a -> ('a, 'e) Stdlib.result Lwt.t) ->
'a option ->
'a option ->
('a option, 'e) Stdlib.result Lwt.t
val map_e :
('a -> ('b, 'trace) Stdlib.result) ->
'a option ->
('b option, 'trace) Stdlib.result
val map_es :
('a -> ('b, 'trace) Stdlib.result Lwt.t) ->
'a option ->
('b option, 'trace) Stdlib.result Lwt.t
filter p o
is Some x
iff o
is Some x
and p o
is true
.
In other words, filter
is like List.filter
if option
is the type of lists of either zero or one elements. In fact, the following equality holds for all p
and for all o
: Option.filter p o = List.hd (List.filter p (Option.to_list o))
The other filter
variants below are also equivalent to their List
counterpart and a similar equality holds.
filter_map
is the Option
counterpart to List
's filter_map
. Incidentally, filter_map f o
is also bind o f
.
filter_s
is filter
where the predicate returns a promise.
filter_map_s
is filter_map
where the function returns a promise.
filter_e
is filter
where the predicate returns a result
.
val filter_map_e :
('a -> ('b option, 'e) Stdlib.result) ->
'a option ->
('b option, 'e) Stdlib.result
filter_map_e
is filter_map
where the function returns a result
.
val filter_es :
('a -> (bool, 'e) Stdlib.result Lwt.t) ->
'a option ->
('a option, 'e) Stdlib.result Lwt.t
filter_es
is filter
where the predicate returns a promise of a result
.
val filter_map_es :
('a -> ('b option, 'e) Stdlib.result Lwt.t) ->
'a option ->
('b option, 'e) Stdlib.result Lwt.t
filter_map_es
is filter_map
where the function returns a promise of a result
.
filter_ok o
is Some x
iff o
is Some (Ok x)
.
filter_error o
is Some x
iff o
is Some (Error x)
.
val iter_e :
('a -> (unit, 'trace) Stdlib.result) ->
'a option ->
(unit, 'trace) Stdlib.result
val iter_es :
('a -> (unit, 'trace) Stdlib.result Lwt.t) ->
'a option ->
(unit, 'trace) Stdlib.result Lwt.t
catch f
is Some (f ())
if f
does not raise an exception, it is None
otherwise.
You should only use catch
when you truly do not care about what exception may be raised during the evaluation of f ()
. If you need to inspect the raised exception, or if you need to pass it along, consider Result.catch
instead.
If catch_only
is set, then only exceptions e
such that catch_only e
is true
are caught.
Whether catch_only
is set or not, this function never catches non-deterministic runtime exceptions of OCaml such as Stack_overflow
and Out_of_memory
.
catch_o f
is equivalent to join @@ catch f
. In other words, it is f ()
if f
doesn't raise any exception, and it is None
otherwise.
catch_only
has the same behaviour and limitations as with catch
.
catch_s f
is a promise that resolves to Some x
if and when f ()
resolves to x
. Alternatively, it resolves to None
if and when f ()
is rejected.
You should only use catch_s
when you truly do not care about what exception may be raised during the evaluation of f ()
. If you need to inspect the raised exception, or if you need to pass it along, consider Result.catch_s
instead.
If catch_only
is set, then only exceptions e
such that catch_only e
is true
are caught.
Whether catch_only
is set or not, this function never catches non-deterministic runtime exceptions of OCaml such as Stack_overflow
and Out_of_memory
.
catch_os f
is like catch_s f
where f
returns a promise that resolves to an option. catch_os f
resolves to None
if f ()
resolves to None
or is rejected. It resolves to Some _
if f ()
does.
catch_only
has the same behaviour and limitations as with catch
.