import { from } from "https://deno.land/x/iter@v3.2.3/lib/generators.ts";
Creates an iterable from IteratorResults returned by a function.
Examples
Example 1
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
f: FromCallback<T>
- 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
.