Module Preface_stdlib.Option

Implementation for Option.t.

Option.t allows to explicitly describe the presence (Some x) or absence (None) of a value. This allows, among other things, the transformation of partial functions into total functions, and forces the explicit handling of the case where None is returned.

Type

type 'a t = 'a option

Implementation

The set of concrete implementations for Option.t.

Functor

module Functor : Preface_specs.FUNCTOR with type 'a t = 'a t

Applicative

Option.t implements Preface_specs.APPLICATIVE and introduces an interface to define Preface_specs.TRAVERSABLE using Option as an iterable structure.

Alternative

module Alternative : Preface_specs.ALTERNATIVE with type 'a t = 'a t

Selective

module Selective : Preface_specs.SELECTIVE with type 'a t = 'a t

Monad

Option.t implements Preface_specs.MONAD and introduces an interface to define Preface_specs.TRAVERSABLE using Option as an iterable structure.

Monad Plus

module Monad_plus : Preface_specs.MONAD_PLUS with type 'a t = 'a t

Foldable

module Foldable : Preface_specs.FOLDABLE with type 'a t = 'a t

Invariant Functor

module Invariant : Preface_specs.INVARIANT with type 'a t = 'a t

Monoid

Option is the Free monoid over a semigroup so wrapping a Preface_specs.SEMIGROUP into an Option gives us a Preface_specs.MONOID with None as a neutral element.

Additional functions

Additional functions to facilitate practical work with Option.t.

val pure : 'a -> 'a t

Create a value from 'a to 'a Option.t.

val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool

Equality between Option.t.

val pp : (Stdlib.Format.formatter -> 'a -> unit) -> Stdlib.Format.formatter -> 'a t -> unit

Formatter for pretty-printing for Option.t.

Producing Option

val if_ : 'a Predicate.t -> 'a -> 'a t

is_ p x produces Some x if p x is true, otherwise, it produces None.

val unless : 'a Predicate.t -> 'a -> 'a t

is_ p x produces Some x if p x is false, otherwise, it produces None.

Composing Option

val or_ : 'a t -> 'a t -> 'a t

or_ a b returns a if a is Some x else it returns b. Equivalent to Alternative.combine.