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

x/iter/mod.ts>create.from

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

Creates an iterable from IteratorResults returned by a function.

Examples

Example 1

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

const upTo6 = from((index) =>
  index < 6 ? { value: index } : { value: index, done: true },
);

for (num of upTo6) {
  console.log(num);
}

// -> 0
// -> 1
// -> 2
// -> 3
// -> 4
// -> 5
// -> 6

Parameters

  • A function which optianally takes the index as an argument and returns the next IteratorResult.

Returns

An iterable containing the value property of the results of f.