Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/fun/mod.ts>array.flatmap

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

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