Skip to content

ap

ap<S, A>(arg): <B>(fn) => State<S, B>

Defined in: Core/State.ts:148

Applies a function wrapped in a State to a value wrapped in a State. The function computation runs first; its output state is the input to the argument computation.

S

A

State<S, A>

<B>(fn): State<S, B>

B

State<S, (a) => B>

State<S, B>

const addCounted = (n: number) => (m: number) => n + m;
const program = pipe(
  State.resolve<number, typeof addCounted>(addCounted),
  State.ap(State.gets((s: number) => s * 2)),
  State.ap(State.gets((s: number) => s)),
);

State.evaluate(3)(program); // 6 + 3 = 9