Legend:
Library
Module
Module type
Parameter
Class
Class type
The option type indicates whether a meaningful value is present. It is frequently used to represent success or failure, using None for failure. To be more descriptive about why a function failed, see the Or_error module.
Usage example from a utop session follows. Hash table lookups use the option type to indicate success or failure when looking up a key.
# let h = Hashtbl.of_alist (module String) [ ("Bar", "Value") ];;
val h : (string, string) Hashtbl.t = <abstr>;;
- : (string, string) Hashtbl.t = <abstr>
# Hashtbl.find h "Foo";;
- : string option = None
# Hashtbl.find h "Bar";;
- : string option = Some "Value"
t >>= f returns a computation that sequences the computations represented by two monad elements. The resulting computation first does t to yield a value v, and then runs the computation returned by f v.
ignore_m t is map t ~f:(fun _ -> ()). ignore_m used to be called ignore, but we decided that was a bad name, because it shadowed the widely used Stdlib.ignore. Some monads still do let ignore = ignore_m for historical reasons.
Extracts the underlying value if present, otherwise returns default.
val value_exn :
?here:Base__.Import.Stdlib.Lexing.position ->?error:Error.t->?message:string ->'at->'a
Extracts the underlying value, or raises if there is no value present. The error raised can be augmented using the ~here, ~error, and ~message optional arguments.
Extracts the underlying value if present, otherwise executes and returns the result of default. default is only executed if the underlying value is absent.
val fold : 'at->init:'acc->f:('acc->'a->'acc)->'acc
On None, returns init. On Some x, returns f init x.
merge a b ~f merges together the values from a and b using f. If both a and b are None, returns None. If only one is Some, returns that one, and if both are Some, returns Some of the result of applying f to the contents of a and b.