Skip to main content
Module

x/fun/state.ts>apply

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Latest
function apply
import { apply } from "https://deno.land/x/fun@v2.0.0/state.ts";

Apply the A value of State<E, A> to the (a: A) => I value of State<E, (a: A) => I>, producing a State<E, I>.

Examples

Example 1

import * as S from "./state.ts";
import { pipe } from "./fn.ts";

const work = pipe(
  S.id<string>(),
  S.map(s => (n: number) => s.repeat(n)),
  S.apply(S.gets(s => s.length))
);

const result1 = work("Hi"); // ["HiHi", "Hi"]
const result2 = work("Hello");
// ["HelloHelloHelloHelloHello", "Hello"]

Returns

<I>(ufai: State<E, (a: A) => I>) => State<E, I>