Skip to main content
Module

x/ahh/mod.ts>Iterator

Opinionated idiomatic features for TypeScript.
Go to Latest
class Iterator
implements Iterable<T>
Abstract
import { Iterator } from "https://deno.land/x/ahh@v0.13.0/mod.ts";

Implemented by classes that can be iterated.

Type Parameters

T extends Some<unknown>

Methods

all(fn: (item: T) => boolean): boolean

Consumes this and returns whether fn returns true for all items.

any(fn: (item: T) => boolean): boolean

Consumes this until fn returns true for an item.

Creates an Iterator that yields items from this and other sequentially.

enumerate(): Iterator<[number, T]>

Creates an Iterator that yields the iteration count and next item.

filter(fn: (item: T) => boolean): Iterator<T>

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

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

Consumes this until fn returns true, and returns the item.

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

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

fuse(): Fuse<T>

Creates an Iterator that exclusively returns None after the first None.

Creates an Iterator that yields items from this and other interspersedly.

Consumes this until it is empty and returns the last item.

map<U extends Some<unknown>>(fn: (item: T) => U): Iterator<U>

Creates an Iterator that calls fn one each item of this.

abstract
next(): Option<T>

Advances the Iterator and yields the next item.

nth(n: number): Option<T>

Consumes n items from this and returns the next item.

peekable(): Peekable<T>

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

skip(n: number): Iterator<T>

Creates an Iterator that skips the first n items.

take(n: number): Iterator<T>

Creates an Iterator that takes the first n items.

zip<U extends Some<unknown>>(other: Iterator<U>): Iterator<[T, U]>

Creates an Iterator that yields items from this and other simultaneously.

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