Skip to main content
Module

x/fun/mod.ts>state.ap

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Go to Latest
function state.ap
import { state } from "https://deno.land/x/fun@v.2.0.0-alpha.11/mod.ts";
const { ap } = state;

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.ap(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>