Functions for the option type.
Options are an Ocaml standard type that can be either None
(undefined)
or Some x
where x can be any value. Options are widely used in Ocaml
to represent undefined values (a little like NULL in C, but in a type
and memory safe way). This module adds some functions for working with
options.
may f (Some x)
calls f x
and may f None
does nothing.
map f (Some x)
returns Some (f x)
and map None
returns None
.
default x (Some v)
returns v
and default x None
returns x
.
map_default f x (Some v)
returns f v
and map_default f x None
returns x
.
is_none None
returns true
otherwise it returns false
.
is_some (Some x)
returns true
otherwise it returns false
.
get (Some x)
returns x
and get None
raises No_value
.
Raised when calling get None
.