std.option

A type that can represent the abscence of a value

Types

type Option a = 
    | None
    | Some a

Option represents a value which may not exist.

Values

let unwrap opt : forall a . Option a -> a

let unwrap_or default opt : forall a . a -> Option a -> a

let to_result err opt : forall a e . e -> Option a -> Result e a

let semigroup a : forall a . Semigroup a -> Semigroup (Option a)

let monoid a : forall a . Semigroup a -> Monoid (Option a)

let former : {
    semigroup : forall a . Semigroup (Option a),
    monoid : forall a . Monoid (Option a)
}

let latter : {
    semigroup : forall a . Semigroup (Option a),
    monoid : forall a . Monoid (Option a)
}

#[implicit]
let eq ?a : forall a . [Eq a] -> Eq (Option a)

Eq a defines equality (==) on a

#[implicit]
let ord ?a : forall a . [Ord a] -> Ord (Option a)

Ord a defines an ordering on a

#[implicit]
let functor : Functor Option

A Functor represents an action on a parameterized type which does not change the structure with the mapped type.

The following laws should hold:

  • map id == id
  • map (f << g) == map f << map g

#[implicit]
let applicative : Applicative Option

A Functor with application.

The following laws should hold:

  • wrap id <*> v = v
  • wrap (<<) <*> u <*> v <*> w = u <*> (v <*> w)
  • wrap f <*> wrap x = wrap (f x)
  • u <*> wrap y = wrap (\g -> g x) <*> u

#[implicit]
let alternative : Alternative Option

A monoid on applicative functors.

#[implicit]
let monad : Monad Option

A generalised interface for imperatively sequencing actions

#[implicit]
let show ?d : forall a . [Show a] -> Show (Option a)

Show a represents a conversion function from a to a readable string.

#[implicit]
let foldable : Foldable Option

Operations over a data structure that can be folded which means that a functions gets called on each element to reduce the structure to a single value (Array, List and Map are all Foldable)

#[implicit]
let traversable : Traversable Option