The Reader monad represents a computation, which can read values from a shared environment, pass values from function to function, and execute sub-computations in a modified environment. It is also usefull when it comes to dependency injections
Implements: Monad
Reader constructor
Param | Type | Description |
---|---|---|
f | function |
A function of the form (e -> a) that is wrapped by the Reader, nothing is executed until it is run with an environment |
Reader constructor that populates the right portion with it's argument. of essentially will lift a value of type a into a Reader
Param | Type | Description |
---|---|---|
v | any |
any value that needs to be lifted to the Reader |
Get a stringified version of the Reader
Apply the function f to the right portion of the Reader
Param | Type | Description |
---|---|---|
f | function |
Function |
Get the function within the Reader
ap allows for values wrapped in a Reader to be applied to functions also wrapped in a Reader. In order to use ap, the Reader must contain a function as its value.
Param | Type | Description |
---|---|---|
t | Reader |
Reader with function as the second element |
Chain together many computations that return a Reader
Param | Type | Description |
---|---|---|
f | function |
Function that returns another Reader |
As Reader is a lazy datatype that requires a shared environment to run, it's instance provides a runWith method that takes in an environment and returns the result of the computation.
Param | Type | Description |
---|---|---|
e | any |
An environment that needs to be passed to the Reader |