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
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