Skip to content

chain

chain<S, A, B>(f): (st) => State<S, B>

Defined in: Core/State.ts:126

Sequences two State computations. The state output of the first is passed as the state input to the second.

Data-last — the first computation is the data being piped.

S

A

B

(a) => State<S, B>

(st): State<S, B>

State<S, A>

State<S, B>

const push = (item: string): State<string[], undefined> =>
  State.modify(stack => [...stack, item]);

const program = pipe(
  push("a"),
  State.chain(() => push("b")),
  State.chain(() => State.get<string[]>()),
);

State.evaluate([])(program); // ["a", "b"]