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

x/iter/lib/transformers.ts>map

A bunch of utilities for working with iterables, many inspired by the native array methods.
Latest
function map
import { map } 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 iterable of the results.

Examples

Example 1

import * as iter from "https://deno.land/x/iter/mod.ts";

const naturals = iter.create.increments(1);
const reciprocals = iter.map(naturals, n => n**-1);
const iterator = reciprocals[Symbol.iterator]();

console.log(iterator.next().value); // -> 1
console.log(iterator.next().value); // -> 0.5
console.log(iterator.next().value); // -> 0.3333333333333333
console.log(iterator.next().value); // -> 0.25
console.log(iterator.next().value); // -> 0.2

Type Parameters

T
optional
U = T

Parameters

it: Iterable<T>
  • The iterable being mapped.
  • A function that accepts up to three arguments. The map function calls f function one time for each item in the iterable.

Returns

An iterable of f applied to items of it.