package containers
Install
Dune Dependency
Authors
Maintainers
Sources
md5=f1c717c9a1015e81253f226ae594f547
sha512=7640b6af5a61e53e52eac51f237a06c5c21597374481af218cf0601c2b9059b96254058b92adb73ce20b1dece4ccaffb99d1b29b235c4dc954619738d8d0de40
doc/containers/CCOpt/index.html
Module CCOpt
Source
Previous Option module
include module type of CCOption
map f o
applies the function f
to the element inside o
, if any.
map_or ~default f o
is f x
if o = Some x
, default
otherwise.
map_lazy default_fn f o
is f x
if o = Some x
, default_fn ()
otherwise.
compare comp o1 o2
compares two options o1
and o2
, using custom comparators comp
for the value. None
is always assumed to be less than Some _
.
equal p o1 o2
tests for equality between option types o1
and o2
, using a custom equality predicate p
.
bind o f
is f v
if o
is Some v
, None
otherwise. Monadic bind.
map2 f o1 o2
maps 'a option
and 'b option
to a 'c option
using f
.
fold f init o
is f init x
if o
is Some x
, or init
if o
is None
. Fold on 0 or 1 element.
filter f o
returns Some x
if o
is Some x
and f x
is true
, or None
if f x
is false
or if o
is None
. Filter on 0 or 1 element.
if_ f x
is Some x
if f x
, None
otherwise.
exists f o
returns true
iff there exists an element for which the provided function f
evaluates to true
.
for_all f o
returns true
iff the provided function f
evaluates to true
for all elements.
get_or ~default o
extracts the value from o
, or returns default
if o
is None
.
value o ~default
is similar to the Stdlib's Option.value
and to get_or
.
get_exn_or msg o
returns x
if o
is Some x
or fails with Invalid_argument msg
if o
is None
.
get_lazy default_fn o
unwraps o
, but if o
is None
it returns default_fn ()
instead.
sequence_l [x1; x2; …; xn]
returns Some [y1; y2; …; yn]
if every xi
is Some yi
. Otherwise, if the list contains at least one None
, the result is None
.
wrap ?handler f x
calls f x
and returns Some y
if f x = y
. If f x
raises any exception, the result is None
. This can be useful to wrap functions such as Map.S.find
.
wrap2 ?handler f x y
is similar to wrap
but for binary functions.
Applicative
Alternatives
or_lazy ~else_ o
is o
if o
is Some _
, else_ ()
if o
is None
.
choice lo
returns the first non-None
element of the list lo
, or None
.
return_if b x
applies Some
or None
depending on the boolean b
. More precisely, return_if false x
is None
, and return_if true x
is Some x
.
Infix Operators
include module type of Infix
f <*> o
returns Some (f x)
if o
is Some x
and None
if o
is None
.
Let operators on OCaml >= 4.08.0, nothing otherwise
Conversion and IO
to_list o
returns [x]
if o
is Some x
or the empty list []
if o
is None
.
of_list l
returns Some x
(x being the head of the list l), or None
if l
is the empty list.
to_result e o
returns Ok x
if o
is Some x
, or Error e
if o
is None
.
to_result_lazy f o
returns Ok x
if o
is Some x
or Error f
if o
is None
.
choice_iter iter
is similar to choice
, but works on iter
. It returns the first Some x
occurring in iter
, or None
otherwise.
choice_seq seq
works on Seq.t
. It returns the first Some x
occurring in seq
, or None
otherwise.
to_gen o
is o
as a gen
. Some x
is the singleton gen
containing x
and None
is the empty gen
.
to_seq o
is o
as a sequence Seq.t
. Some x
is the singleton sequence containing x
and None
is the empty sequence. Same as Stdlib.Option.to_seq
Renamed from to_std_seq
since 3.0.
to_iter o
returns an internal iterator, like in the library Iter
.