monex v0.1.3 MonEx

A collection of simple monadic types: Option, Result.

Summary

Functions

Applies function returning to content of monadic type

Calls supplied function with content of monadic type as an argument, expecting no return

Applies function to content of monadic type

Types

monadic()
monadic() :: Option.t | Result.t

Functions

flat_map(arg, f)
flat_map(monadic, (term -> monadic)) :: monadic

Applies function returning to content of monadic type:

Example: inverse = fn (x) -> if x == 0, do: none(), else: some(1/x) end some(5) |> flat_map(f) == some(1/5) some(0) |> flat_map(f) == none()

foreach(arg, f)
foreach(monadic, (term -> no_return)) :: no_return

Calls supplied function with content of monadic type as an argument, expecting no return

map(arg, f)
map(monadic, (term -> term)) :: monadic

Applies function to content of monadic type:

Example: f = fn (x) -> x * 2 end some(5) |> map(f) == some(10) none() |> map(f) == none()