Skip to main content
Module

x/better_iterators/mod.ts>LazyShared

Chainable iterators (sync and async) for TypeScript, with support for opt-in, bounded parallelism
Go to Latest
interface LazyShared
import { type LazyShared } from "https://deno.land/x/better_iterators@v1.1.0/mod.ts";

Shared interface for Lazy and LazyAsync. (Note: LazyAsync implements some methods that are not shared.)

You shouldn't need to interact with these classes or this interface directly, though. You can convert to the appropriate one with lazy.

Operations on lazy iterators consume the underlying iterator. You should not use them again.

Methods

map<Out>(transform: Transform<T, Out>): LazyShared<Out>

Apply transform to each element.

Works like Array#map.

filter(f: Filter<T>): LazyShared<T>

Keeps only items for which f is true.

limit(count: number): LazyShared<T>

Limit the iterator to returning at most count items.

toArray(): Awaitable<Array<T>>

Collect all items into an array.

also(fn: (t: T) => void): LazyShared<T>

Injects a function to run on each T as it is being iterated.

partition(f: Filter<T>): Awaitable<Partitioned<T>>

Partition items into matches and others according to Filter f.

first(): Awaitable<T>

Get the first item. @throws if there are no items.

firstOr<D>(defaultValue: D): Awaitable<T | D>

Get the first item. Returns defaultValue if there is no first item.

skip(count: number): LazyShared<T>

Skip (up to) the first count elements

groupBy<Key>(keyFn: Transform<T, Key>): Awaitable<Map<Key, T[]>>

Given keyFn, use it to extract a key from each item, and create a Map grouping items by that key.

associateBy<Key>(uniqueKeyFn: Transform<T, Key>): Awaitable<Map<Key, T>>

Given uniqueKeyFn, use it to extract a key from each item, and create a 1:1 map from that to each item.

flatten(): LazyShared<Flattened<T>>

Flattens a Lazy<Iterable> to a Lazy