Option (imandrax-ocaml.Imandrax_ocaml_prelude.Prelude_extracted.Option)

### Option module

The option type `type 'a option = None | Some of 'a` is useful for representing partial functions and optional values.

`type 'a t = 'a option`
`val map : ('a -> 'b) -> 'a option -> 'b option`

Map over the option.

- `map f None = None`
- `map f (Some x) = Some (f x)`

`val map_or : default:'a -> ('b -> 'a) -> 'b option -> 'a`
`val is_some : 'a option -> bool`

Returns `true` iff the argument is of the form `Some x`

`val is_none : 'a option -> bool`

Returns `true` iff the argument is `None`

`val return : 'a -> 'a option`

Wrap a value into an option. `return x = Some x`

`val (>|=) : 'a option -> ('a -> 'b) -> 'b option`

Infix alias to `map`

`val flat_map : ('a -> 'b option) -> 'a option -> 'b option`

Monadic operator, useful for chaining multiple optional computations

`val (>>=) : 'a option -> ('a -> 'b option) -> 'b option`

Infix monadic operator, useful for chaining multiple optional computations together. It holds that `(return x >>= f) = f x`

`val or_ : 'a option -> 'a option -> 'a option`

Choice of a value

- `or_ None x = x`
- `or_ (Some y) x = Some y`

`val (<+>) : 'a option -> 'a option -> 'a option`
`val exists : ('a -> bool) -> 'a option -> bool`
`val for_all : ('a -> bool) -> 'a option -> bool`
`val get_or : default:'a -> 'a option -> 'a`
`val fold : ('a -> 'b -> 'a) -> 'a -> 'b option -> 'a`
`val (<$>) : ('a -> 'b) -> 'a option -> 'b option`

`f <$> x = map f x`

`val monoid_product : 'a option -> 'b option -> ('a * 'b) option`
`val let+ : 'a option -> ('a -> 'b) -> 'b option`
`val and+ : 'a option -> 'b option -> ('a * 'b) option`
`val let* : 'a option -> ('a -> 'b option) -> 'b option`
`val and* : 'a option -> 'b option -> ('a * 'b) option`