import { lazyObserver } from "https://deno.land/x/iter@v3.2.3/lib/effectors.ts";
Performs the specified action for each item in an iterable when the returned
iterable is iterated over. Like forEach | forEach
but non-consuming.
Can be used to observe items of an iterable as they are released.
Examples
Example 1
Example 1
import * as iter from "https://deno.land/x/iter/mod.ts";
const naturals = iter.create.increments(1);
const observed = iter.lazyObserver(naturals, (x) => console.log(x));
const iterator = observed[Symbol.iterator]();
iterator.next();
// -> 1
iterator.next();
// -> 2
iterator.next();
// -> 3
Parameters
it: Iterable<T>
- The iterable being observed.
f: ForEachCallback<T>
- A function that accepts up to three arguments.
forEach
callsf
one time for each item in the iterable.
Returns
- The observed version of
it
.