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

x/iter/mod.ts>lazyObserver

A bunch of utilities for working with iterables, many inspired by the native array methods.
Latest
function lazyObserver
import { lazyObserver } from "https://deno.land/x/iter@v3.2.3/mod.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

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.
  • A function that accepts up to three arguments. forEach calls f one time for each item in the iterable.

Returns

  • The observed version of it.