Skip to main content
Module

x/ahh/mod.ts>Iterator

Opinionated idiomatic type-safety functions.
Go to Latest
class Iterator
implements Iterable<T>
Abstract
import { Iterator } from "https://deno.land/x/ahh@v0.12.0/mod.ts";

An interface type that can be iterated over.

Methods

chain(other: Iterator<T>): Chain<T>

Creates an Iterator over two Iterators sequentially.

count(): number

Consumes an Iterator and returns the number of iterations.

enumerate(): Enumerate<T>

Creates an Iterator that yields the iteration count as well as the next value.

filter(fn: (_: T) => boolean): Filter<T>

Creates an Iterator that yields items for which fn returns true.

find(fn: (_: T) => boolean): Option<T>

Consumes an Iterator until fn returns true and returns the item.

fold<U>(init: U, fn: (init: U, _: T) => U): U

Consumes an Iterator and calls fn on each item to collect them into init.

forEach(fn: (_: T) => unknown): void

Consumes an Iterator and calls fn on each item.

Consumes an Iterator and returns the last item.

map<U>(fn: (_: T) => U): Map<T, U>

Creates an Iterator that yields each item mapped via fn.

abstract
next(): Option<T>

Advances the iterator and returns the next item.

nth(n: number): Option<T>

Consumes n items from the Iterator and returns the next item.

peekable(): Peekable<T>

Creates an Iterator that can be return the next item without consuming it.

skip(n: number): Skip<T>

Creates an Iterator that skips the first n items.

skipWhile(fn: (_: T) => boolean): SkipWhile<T>

Creates an Iterator that skips items while fn returns true.

take(n: number): Take<T>

Creates an Iterator that takes the first n items.

takeWhile(fn: (_: T) => boolean): TakeWhile<T>

Creates an Iterator that takes items while fn returns true.

zip<U>(other: Iterator<U>): Zip<T, U>

Creates an Iterator over two Iterators simultaneously.

[Symbol.iterator](): globalThis.Iterator<T>