Monad.Reader

The Reader monad.

Monad that encapsulates a read-only value/shared environment.

Examples

iex> require Monad.Reader, as: Reader
iex> import Reader
iex> r = Reader.m do
...>       let a = 2
...>       b <- ask
...>       return a + b
...>     end
iex> Reader.run(10, r)
12

Summary

Functions

Ask for the Reader monad’s value

Callback implementation for Monad.bind/2

Set a different value locally for the Reader monad

Inject x into a Reader monad

Run Reader monad r by supplying it with value x

Macros

Monad do-notation

Types

Functions

ask()

Specs

ask :: reader_m

Ask for the Reader monad’s value.

bind(r, f)

Specs

bind(reader_m, (any -> reader_m)) :: reader_m

Callback implementation for Monad.bind/2.

local(r, f)

Specs

local(reader_m, (any -> any)) :: reader_m

Set a different value locally for the Reader monad.

return(x)

Specs

return(any) :: reader_m

Inject x into a Reader monad.

run(x, r)

Specs

run(any, reader_m) :: any

Run Reader monad r by supplying it with value x.

Macros

m(list)

Monad do-notation.

See the Monad module documentation and the Monad.Readermodule documentation