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.
Represents a computation that expects a context that when run returns the result of the computation.
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.
reader : value -> Reader env value
Returns a Reader that when run will produce the value provided, no matter what the context.
local : (context -> context) -> Reader context someA -> Reader context someA
Modify the context of a Reader
map : (someA -> someB) -> Reader context someA -> Reader context someB
Transform a Reader
andThen : (someA -> Reader context someB) -> Reader context someA -> Reader context someB
Chain together Readers