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

x/iter/mod.ts>create.endlessFrom

A bunch of utilities for working with iterables, many inspired by the native array methods.
Latest
function create.endlessFrom
import { create } from "https://deno.land/x/iter@v3.2.3/mod.ts";
const { endlessFrom } = create;

Creates an endless iterable from the return values of a function.

Examples

Example 1

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

const evenNumbers = iter.create.endlessFrom(index => 2 * index);
const iterator = evenNumbers[Symbol.iterator]();

console.log(iterator.next().value); // -> 0
console.log(iterator.next().value); // -> 2
console.log(iterator.next().value); // -> 4
console.log(iterator.next().value); // -> 6
console.log(iterator.next().value); // -> 8
console.log(iterator.next().value); // -> 10

Parameters

  • A function which optionally takes the index as an argument and returns the next item in the iterable.

Returns

An iterable containing the results of f.