import { map } from "https://deno.land/x/aitertools@0.6.0/src/map.ts";
Transforms every element of the iterable source
into a new iterable.
import { map } from "./map.ts";
import { count } from "./infinite.ts";
const iterable = map((v: number) => v * 2, count());
for await (const value of iterable) console.log(value);
The above example will print the following and keep going forever:
0
2
4
6
(...)
The fn
function can take an additional argument, which is the index of the
element in the iterable.
import { map } from "./map.ts";
const iterable = map(
(v: string, i: number) => `${i}. ${v.toUpperCase()}`,
["foo", "bar", "baz", "qux"]
);
for await (const value of iterable) console.log(value);
The above example will print the following 4 lines:
0. FOO
1. BAR
2. BAZ
3. QUX
Transforms every element of the iterables into a new single iterable. If iterable sources are of different lengths, the resulting iterable will be of the same length as the shortest iterable.
import { map } from "./map.ts";
import { count } from "./infinite.ts";
const iterable = map(
(s: string, n: number) => `${s} ${n}`,
["foo", "bar", "baz", "qux"],
count()
);
for await (const value of iterable) console.log(value);
The above example will print the following 4 lines:
foo 0
bar 1
baz 2
qux 3
The fn
function can take an additional argument, which is the index of the
element in the iterable.
import { map } from "./map.ts";
import { count } from "./infinite.ts";
const iterable = map(
(s: string, n: number, i: number) => `${i}. ${s} ${n}`,
["foo", "bar", "baz", "qux"],
count(0, 5)
);
for await (const value of iterable) console.log(value);
The above example will print the following 4 lines:
0. foo 0
1. bar 5
2. baz 10
3. qux 15
Parameters
A function that takes elements of the same position in the sources and returns a single transformed element. It can be either async or sync.
The first iterable to transform with fn
.
Its each element will be passed as the first argument to
fn
.
Transforms every element of the iterables into a new single iterable. If iterable sources are of different lengths, the resulting iterable will be of the same length as the shortest iterable.
Parameters
A function that takes elements of the same position in the sources and returns a single transformed element. It can be either async or sync.
The first iterable to transform with fn
.
Its each element will be passed as the first argument to
fn
.
The second iterable iterable to transform with fn
.
Its each element will be passed as the second argument to
fn
.
Transforms every element of the iterables into a new single iterable. If iterable sources are of different lengths, the resulting iterable will be of the same length as the shortest iterable.
Parameters
A function that takes elements of the same position in the sources and returns a single transformed element. It can be either async or sync.
The first iterable to transform with fn
.
Its each element will be passed as the first argument to
fn
.
The second iterable iterable to transform with fn
.
Its each element will be passed as the second argument to
fn
.
The third iterable iterable to transform with fn
.
Its each element will be passed as the third argument to
fn
.
Transforms every element of the iterables into a new single iterable. If iterable sources are of different lengths, the resulting iterable will be of the same length as the shortest iterable.
Parameters
A function that takes elements of the same position in the sources and returns a single transformed element. It can be either async or sync.
The first iterable to transform with fn
.
Its each element will be passed as the first argument to
fn
.
The second iterable iterable to transform with fn
.
Its each element will be passed as the second argument to
fn
.
The third iterable iterable to transform with fn
.
Its each element will be passed as the third argument to
fn
.
The fourth iterable iterable to transform with fn
.
Its each element will be passed as the fourth argument to
fn
.