Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/ahh/src/iter/mod.ts>I

Idiomatic type-safety functions.
Go to Latest
class I
import { I } from "https://deno.land/x/ahh@v0.10.3/src/iter/mod.ts";

Functionality for Iterator.

Static Methods

any<T>(iter: Iterator<T>, f: (_: T) => boolean): boolean

Consumes an Iterator until f returns true, and returns true if it does.

chain<T>(iterA: Iterator<T>, iterB: Iterator<T>): Iterator<T>

Creates an Iterator that iterates over two other Iterators sequentially.

count<T>(iter: Iterator<T>): number

Consumes an Iterator and returns the number of iterations.

empty<T>(): Iterator<T>

Creates an Iterator that yields nothing.

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

Creates an Iterator which yields the current iteration as well as the next value.

filter<T>(iter: Iterator<T>, f: (_: T) => boolean): Iterator<T>

Creates an Iterator that returns items when f returns true.

find<T>(iter: Iterator<T>, f: (_: T) => boolean): Option<T>

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

flatten<T>(iter: Iterator<Iterator<T>>): Iterator<T>

Creates an Iterator that flattens a layer of nested Iterators.

fn<T>(f: Iterator<T>["next"]): Iterator<T>

Creates an Iterator where each iteration calls f.

fold<T, U>(
iter: Iterator<T>,
init: U,
f: (_: U, _1: T) => U,
): U

Consumes an Iterator and calls f on each item to fold it into init.

forEach<T>(iter: Iterator<T>, f: (_: T) => void): void

Consumes an Iterator and calls f on each item.

inspect<T>(iter: Iterator<T>, f: (_: T) => unknown): Iterator<T>

Creates an Iterator that calls f on each item and yeilds the original item.

iter<T>(iter: Iterable<T>): Iterator<T>

Creates an Iterator from an Iterable.

last<T>(iter: Iterator<T>): Option<T>

Consumes an Iterator and returns the last item.

map<T, U>(iter: Iterator<T>, f: (_: T) => U): Iterator<U>

Creates an Iterator that calls f on each item and yeilds the result.

nextIf<T>(iter: Peekable<T>, f: (_: T) => boolean): Option<T>

Consume the next value of an Iterator and return it if f returns true.

nth<T>(iter: Iterator<T>, n: number): Option<T>

Consumes an Iterator up to n and returns the item.

once<T>(item: T): Iterator<T>

Creates an Iterator that yields exactly one item.

peekable<T>(iter: Iterator<T>): Peekable<T>

Creates an Iterator that is Peekable.

repeat<T>(item: T): Iterator<T>

Creates an Iterator that endlessly yields an item.

Example

import { I } from "./mod.ts";

const iter = I.repeat(1);

console.log(iter.next()); // 1
console.log(iter.next()); // 1
console.log(iter.next()); // 1
skip<T>(iter: Iterator<T>, n: number): Iterator<T>

Creates an Iterator that skips the first n items.

skipWhile<T>(iter: Iterator<T>, f: (_: T) => boolean): Iterator<T>

Creates an Iterator that skips items while f returns true.

successors<T>(first: Option<T>, f: (_: T) => Option<T>)

Creates an Iterator where each successive item is computed from the preceding one.

take<T>(iter: Iterator<T>, n: number): Iterator<T>

Creates an Iterator that yields the first n items.

takeWhile<T>(iter: Iterator<T>, f: (_: T) => boolean)

Creates an Iterator that yields items while f returns true.

zip<T, U>(iterA: Iterator<T>, iterB: Iterator<U>): Iterator<[T, U]>

Creates an Iterator that iterates over two other Iterators simultaneously.

If either Iterator returns None, so will this Iterator.