import { flatMap } from "https://deno.land/x/iter@v3.2.3/lib/transformers.ts";
Lazily calls a defined callback function for each element of an iterable, and returns a new flattened iterable of the results by one level.
Examples
Example 1
Example 1
import * as iter from "https://deno.land/x/iter/mod.ts";
const numbers = iter.create.increments(1);
const squares = iter.flatMap(numbers, n => [n, n*n]);
const iterator = squares[Symbol.iterator]();
console.log(iterator.next().value); // -> 1
console.log(iterator.next().value); // -> 1
console.log(iterator.next().value); // -> 2
console.log(iterator.next().value); // -> 4
console.log(iterator.next().value); // -> 3
console.log(iterator.next().value); // -> 9
Type Parameters
optional
U = TParameters
it: Iterable<T>
- The iterable being mapped.
f: FlatMapCallback<T, U>
- A function that accepts up to three arguments. The
flatMap function calls
f
function one time for each item in the iterable.