Skip to main content
Module

x/fun/array.ts>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 ap
import { ap } from "https://deno.land/x/fun@v2.0.0-alpha.6/array.ts";

Given an array of functions ReadonlyArray<A -> I> and a ReadonlyArray apply every function in the function array to every value in the ReadonlyArray. This implementation loops first over the functions, and then over the values, so the order of results will be [fn1(val1), fn2(val1), fn3(val1), ..., fn1(val2), fn2(val2), ... fn1(valN), ... fnN(valN)].

Examples

Example 1

import * as A from "./array.ts";
import { pipe } from "./fn.ts";

const result = pipe(
  A.of((n: number) => n + 1),
  A.ap(A.array(1, 2, 3)),
); // [2, 3, 4]

Parameters

ua: ReadonlyArray<A>

Returns

<I>(ufai: ReadonlyArray<(a: A, index: number) => I>) => ReadonlyArray<I>