Skip to content

Latest commit

 

History

History
83 lines (55 loc) · 2.48 KB

reader.md

File metadata and controls

83 lines (55 loc) · 2.48 KB

Reader

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(f)

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)

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

Reader.toString()

Get a stringified version of the Reader

Reader.map(f)

Apply the function f to the right portion of the Reader

Param Type Description
f function Function

Reader.getValue()

Get 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 Reader with function as the second element

Reader.chain(f)

Chain together many computations that return a Reader

Param Type Description
f function Function that returns another Reader

Reader.runWith(e)

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