Module Monads.OptionMonad

OptionMonad

A module providing monadic operations for the option type.

val return : 'a -> 'a option

return x wraps a value x into an option.

val bind : 'a option -> ('a -> 'b option) -> 'b option

bind opt f applies the function f to the value inside opt if it is Some, otherwise returns None.

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

Infix operator for bind. Equivalent to bind opt f.

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

opt >>| f applies the function f to the value inside opt if it is Some, and wraps the result in Some.

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

opt1 >>! opt2 returns opt1 if it is Some, otherwise returns opt2.

val fold_left : ('a -> 'b -> 'a option) -> 'a -> 'b list -> 'a option

fold_left f acc lst folds over the list lst using the function f and an accumulator acc, where f returns an option. If any step returns None, the entire computation returns None.

val map : ('a -> 'b option) -> 'a option list -> 'b option list

map f lst applies the function f to each element of the list lst, where f returns an option. The result is a list of option values.

val iter : ('a -> unit) -> 'a list -> unit

iter f lst applies the function f to each element of the list lst.