import { type LazyShared } from "https://deno.land/x/better_iterators@v1.5.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 use lazy to automatically instantiate the correct one.
Operations on lazy iterators consume the underlying iterator. You should not use them again.
Methods
Apply transform
to each element.
Works like Array#map.
Asynchronously transform elements in parallel.
Partition items into matches
and others
according to Filter f
.
Adds a valueFn
to extract that value (instead of T) into a group.
Given uniqueKeyFn
, use it to extract a key from each item, and create a
1:1 map from that to each item.
Takes an additional valueFn
to extract a value from T
. The returned
map maps from Key to Value. (instead of Key to T)
Joins multiple string values into a string.
Sums a Lazy iterator of number
s.
This is equivalent to:
import { lazy, range } from "./mod.ts"
range({to: 10}).fold(0, (a, b) => a + b)
Averages numbers from the Lazy iterable.
Will return NaN if no numbers exist.
Note: This algorithm does a simple left-to-right accumulation of the sum, so can suffer from loss of precision when summing things with vastly different scales, or working with sums over Number.MAX_SAFE_INTEGER.
Get a "peekable" iterator, which lets you peek() at the next item without removing it from the iterator.
Iterate by chunks of a given size formed from the underlying Iterator.
Each chunk will be exactly size
until the last chunk, which may be
from 1-size items long.
Repeat items count
times.
import { range } from "./mod.ts"
let nine = range({to: 3}).repeat(3).sum()