bigbinary/elm-reader/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

Reader

A Reader helps in solving the problem of passing down the same values to many functions. If there are computations that read value from a shared environment or configurations to be passed around, a Reader can be used in all such cases. It is also often used as a way of doing dependency injections.

Definition

type Reader context someA
= Reader (context -> someA)

Represents a computation that expects a context that when run returns the result of the computation.

Helpers

run : Reader context someA -> context -> someA

A Reader expects an environment or a context to run, the run function takes in a Reader and the context it expects and returns the result of the computation.

ask : Reader context context

Returns a Reader that when run with a context value gives back the context value as is

Mapping

map : (someA -> someB) -> Reader context someA -> Reader context someB

Transform a Reader

Chaining

(someA -> Reader context someB)
-> Reader context someA
-> Reader context someB

Chain together Readers