Reader
Reader:
object
Defined in: Core/Reader.ts:26
Type Declaration
Section titled “Type Declaration”ap: <
R,A>(arg) => <B>(data) =>Reader<R,B>
Applies a function wrapped in a Reader to a value wrapped in a Reader. Both Readers see the same environment.
Type Parameters
Section titled “Type Parameters”R
A
Parameters
Section titled “Parameters”Reader<R, A>
Returns
Section titled “Returns”<B>(data) => Reader<R, B>
Example
Section titled “Example”ask: <
R>() =>Reader<R,R>
Returns the full environment as the result. The fundamental way to access the environment in a pipeline.
Type Parameters
Section titled “Type Parameters”R
Returns
Section titled “Returns”Reader<R, R>
Example
Section titled “Example”asks: <
R,A>(f) =>Reader<R,A>
Projects a value from the environment using a selector function.
Equivalent to pipe(Reader.ask(), Reader.map(f)) but more direct.
Type Parameters
Section titled “Type Parameters”R
A
Parameters
Section titled “Parameters”(env) => A
Returns
Section titled “Returns”Reader<R, A>
Example
Section titled “Example”bind: <
K,R,A,B>(key,f) => (data) =>Reader<R,A&{ [P in string]: B }>
Evaluates a new Reader using the current accumulator and attaches the output to a new key.
Type Parameters
Section titled “Type Parameters”K extends string
R
A
B
Parameters
Section titled “Parameters”K
(a) => Reader<R, B>
Returns
Section titled “Returns”(data) => Reader<R, A & { [P in string]: B }>
Example
Section titled “Example”bindTo
Section titled “bindTo”bindTo: <
K>(key) => <R,A>(data) =>Reader<R,{ [P in string]: A }>
Lifts a Reader value into an accumulator object.
Type Parameters
Section titled “Type Parameters”K extends string
Parameters
Section titled “Parameters”K
Returns
Section titled “Returns”<R, A>(data) => Reader<R, { [P in string]: A }>
Example
Section titled “Example”chain: <
R,A,B>(f) => (data) =>Reader<R,B> =chainReader
Sequences two Readers. Both see the same environment.
The output of the first is passed to f, which returns the next Reader.
Type Parameters
Section titled “Type Parameters”R
A
B
Parameters
Section titled “Parameters”(a) => Reader<R, B>
Returns
Section titled “Returns”(data) => Reader<R, B>
Example
Section titled “Example”local: <
R2,R>(f) => <A>(data) =>Reader<R2,A>
Adapts a Reader to work with a different (typically wider) environment by transforming the environment before passing it to the Reader. This lets you compose Readers that expect different environments.
Type Parameters
Section titled “Type Parameters”R2
R
Parameters
Section titled “Parameters”(env) => R
Returns
Section titled “Returns”<A>(data) => Reader<R2, A>
Example
Section titled “Example”map: <
R,A,B>(f) => (data) =>Reader<R,B> =mapReader
Transforms the value produced by a Reader.
Type Parameters
Section titled “Type Parameters”R
A
B
Parameters
Section titled “Parameters”(a) => B
Returns
Section titled “Returns”(data) => Reader<R, B>
Example
Section titled “Example”resolve
Section titled “resolve”resolve: <
R,A>(value) =>Reader<R,A>
Lifts a pure value into a Reader. The environment is ignored.
Type Parameters
Section titled “Type Parameters”R
A
Parameters
Section titled “Parameters”A
Returns
Section titled “Returns”Reader<R, A>
Example
Section titled “Example”run: <
R>(env) => <A>(data) =>A
Runs a Reader by supplying the environment. Use this at the edge of your program where the environment is available.
Type Parameters
Section titled “Type Parameters”R
Parameters
Section titled “Parameters”R
Returns
Section titled “Returns”<A>(data) => A
Example
Section titled “Example”tap: <
R,A>(f) => (data) =>Reader<R,A>
Executes a side effect on the produced value without changing the Reader. Useful for logging or debugging inside a pipeline.
Type Parameters
Section titled “Type Parameters”R
A
Parameters
Section titled “Parameters”(a) => void
Returns
Section titled “Returns”(data) => Reader<R, A>