Reader
Reader:
object
Defined in: Core/Reader.ts:26
Type Declaration
Section titled “Type Declaration”apply: <
R2,A>(arg) => <B,R1>(reader) =>Reader<R1&R2,B>
Applies a function wrapped in a Reader to a value wrapped in a Reader. Combines environment requirements via intersection.
Type Parameters
Section titled “Type Parameters”R2
A
Parameters
Section titled “Parameters”Reader<R2, A>
Returns
Section titled “Returns”<B, R1>(reader) => Reader<R1 & R2, B>
chain to sequence dependent Reader computations.
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>
make to lift a static value that ignores the environment.
Example
Section titled “Example”assign
Section titled “assign”assign: <
K,R2,A,B>(key,transform) => <R1>(reader) =>Reader<R1&R2,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
R2
A
B
Parameters
Section titled “Parameters”K
transform
Section titled “transform”(value) => Reader<R2, B>
Returns
Section titled “Returns”<R1>(reader) => Reader<R1 & R2, A & { [P in string]: B }>
assignTo to initialize the accumulator record.
Example
Section titled “Example”assignTo
Section titled “assignTo”assignTo: <
K>(key) => <R,A>(reader) =>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>(reader) => Reader<R, { [P in string]: A }>
assign to accumulate subsequent Reader values into the object.
Example
Section titled “Example”chain: <
A,R2,B>(transform) => <R1>(reader) =>Reader<R1&R2,B> =chainReader
Sequences two Readers. Both see the environment.
The output of the first is passed to transform, which returns the next Reader.
Type Parameters
Section titled “Type Parameters”A
R2
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(value) => Reader<R2, B>
Returns
Section titled “Returns”<R1>(reader) => Reader<R1 & R2, B>
map to transform the value without returning a new Reader.
Example
Section titled “Example”local: <
R2,R>(transform) => <A>(reader) =>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”transform
Section titled “transform”(env) => R
Returns
Section titled “Returns”<A>(reader) => Reader<R2, A>
run to supply the final environment rather than transforming it.
Example
Section titled “Example”make: <
R,A>(value) =>Reader<R,A>
Lifts a pure value into a Reader. The environment is ignored.
Type Parameters
Section titled “Type Parameters”R = unknown
A = never
Parameters
Section titled “Parameters”A
Returns
Section titled “Returns”Reader<R, A>
ask to retrieve the environment instead of ignoring it.
Example
Section titled “Example”map: <
A,B>(transform) => <R>(reader) =>Reader<R,B> =mapReader
Transforms the value produced by a Reader.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(value) => B
Returns
Section titled “Returns”<R>(reader) => Reader<R, B>
chain to sequence a computation that also reads from the environment.
Example
Section titled “Example”run: <
R>(env) => <A>(reader) =>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>(reader) => A
local to adapt the environment before execution.
Example
Section titled “Example”tap: <
A>(sideEffect) => <R>(reader) =>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”A
Parameters
Section titled “Parameters”sideEffect
Section titled “sideEffect”(value) => void
Returns
Section titled “Returns”<R>(reader) => Reader<R, A>
map to transform the value instead of executing a side effect.