Reader
Reader
The Reader monad represents a computation that can read values from a shared environment, pass values from function to function, and execute sub-computations in a modified environment. It is also useful for dependency injection.
Implements: Monad
Reader(f)
The 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.of(v)
The Reader constructor that populates the right portion with its argument. of essentially lifts a value of type a into a Reader.
| Param | Type | Description |
|---|---|---|
| v | any |
Any value that needs to be lifted into the Reader |
Reader.toString()
Gets a stringified version of the Reader.
Reader.map(f)
Applies the function f to the right portion of the Reader.
| Param | Type | Description |
|---|---|---|
| f | function |
Function |
Reader.getValue()
Gets the function within the Reader.
Reader.ap(t)
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 |
A Reader with a function as its value |
Reader.chain(f)
Chains together many computations that return a Reader.
| Param | Type | Description |
|---|---|---|
| f | function |
Function that returns another Reader |
Reader.runWith(e)
Since Reader is a lazy datatype that requires a shared environment to run, its instance provides a runWith method. This method 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 |