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

x/iter/mod.ts>peekable

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

Generates a peekable iterator from the provided iterable (See Peekable). Note that unlike other transformers, this returns an extended IterableIterator rather than an iterable. Inspired by Rust's std::iter::Peekable.

Examples

Example 1

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

const peekable = iter.peekable(iter.create.range(5));

for (const n of peekable) {
  assert(n + 1 === peekable.peek().value ||  peekable.peek().done);
}

Parameters

iter: Iterable<T>
  • The iterable to make peekable

Returns

A peekable iterator on the items of iter.