Module NesOption

Options

Standard Library

This module contains everything defined for lists by the OCaml standard library. For these functions, refer to the official documentation.

include module type of Stdlib.Option
type !'a t = 'a option =
  1. | None
  2. | Some of 'a
val none : 'a option
val some : 'a -> 'a option
val value : 'a option -> default:'a -> 'a
val get : 'a option -> 'a
val bind : 'a option -> ('a -> 'b option) -> 'b option
val join : 'a option option -> 'a option
val map : ('a -> 'b) -> 'a option -> 'b option
val fold : none:'a -> some:('b -> 'a) -> 'b option -> 'a
val iter : ('a -> unit) -> 'a option -> unit
val is_none : 'a option -> bool
val is_some : 'a option -> bool
val equal : ('a -> 'a -> bool) -> 'a option -> 'a option -> bool
val compare : ('a -> 'a -> int) -> 'a option -> 'a option -> int
val to_result : none:'e -> 'a option -> ('a, 'e) Stdlib.result
val to_list : 'a option -> 'a list
val to_seq : 'a option -> 'a Stdlib.Seq.t

Additional Contents

val compare_lwt : ('a -> 'a -> int Lwt.t) -> 'a t -> 'a t -> int Lwt.t

Same as compare when the comparison function returns an Lwt value.

val choose : tie:('a -> 'a -> 'a) -> 'a t -> 'a t -> 'a t

choose ~tie first second returns Some x when one of first or second is Some x and the other is bottom. If they are both None, None is returned. If they are both Some, tie is called.

val fail : 'a -> 'a -> 'a

For NesOption.choose's tie argument. Fails.

val second : 'a -> 'a -> 'a

For NesOption.choose's tie argument. Takes the second argument.

val concat : ('a -> 'a -> 'a) -> 'a option -> 'a option -> 'a option

Concatenation of the monoid given the concatenation of the embedded one.

val concat_l : ('a -> 'a -> 'a) -> 'a option list -> 'a option

Same as concat but for a list of options.

val return : 'a -> 'a option

Same as some.

val first : 'a option list -> 'a option

Return the first element of the list that is not None.

val to_string : string option -> string

Maps None to "" and Some s to s.

val of_string_nonempty : string -> string option

Maps "" to None and other strings to Some.

val fold' : none:(unit -> 'a) -> some:('b -> 'a) -> 'b option -> 'a

Variant of fold where ~none is a thunk.

val value' : default:(unit -> 'a) -> 'a option -> 'a

Variant of default where ~default is a thunk.