Skip to main content
Module

x/fun/array.ts>chain

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

Given a function A -> ReadonlyArray and a ReadonlyArray apply the function to every value in the array and combine all results, returning a ReadonlyArray.

Examples

Example 1

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

const result = pipe(
  A.range(3, 1, 3), // [1, 4, 7]
  A.chain(n => [n, n + 1, n + 2]), // ie. 1 -> [1, 2, 3]
); // [1, 2, 3, 4, 5, 6, 7, 8, 9]

Parameters

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

Returns

(ua: ReadonlyArray<A>) => ReadonlyArray<I>