Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AsyncPeekable<T>

An iterator with a peek. method that can look one element in advance.

Do not instantiate this directly, instead use the peekable method in IterPlus or AsyncIterPlus.

Type parameters

  • T

    The item type of the iterator.

Hierarchy

Index

Constructors

  • new AsyncPeekable<T>(iter: AsyncIterator<T, any, undefined>): AsyncPeekable<T>

Properties

internal: AsyncIterator<T, any, undefined>

The internal iterator that this wraps around.

storedVal: { has: true; val: IteratorResult<T, any> } | { has: false; val: unknown }

Methods

  • [asyncIterator](): AsyncIterator<T, any, undefined>
  • allEqual(): Promise<boolean>
  • Checks if every element in this iterator is equal.

    This function is short-circuiting, so it stops on the first inequality.

    Returns Promise<boolean>

    If every element is equal, or true if the iterator has one or less elements.

  • allEqualBy(cmp: (first: T, second: T) => PromiseOrValue<boolean>): Promise<boolean>
  • Checks if every element in this iterator is equal, using a comparison function.

    This function is short-circuiting, so it stops on the first inequality.

    Parameters

    Returns Promise<boolean>

    If every element is equal, or true if the iterator has one or less elements.

  • allEqualWith<K>(key: (elem: T) => PromiseOrValue<K>): Promise<boolean>
  • Checks if every element in this iterator is equal, using a key function.

    This function is short-circuiting, so it stops on the first inequality.

    Type parameters

    • K

      The type of the key.

    Parameters

    Returns Promise<boolean>

    If every element is equal, or true if the iterator has one or less elements.

  • average(): Promise<T>
  • Returns an iterator yielding non-overlapping chunks of the iterator.

    If there aren't enough elements to fill a chunk, the last chunk will be smaller than the chunk size.

    If you want gaps between the chunks, consider using windows with the appropriate interval instead.

    Parameters

    • chunkSize: number

      The chunk size.

    Returns AsyncIterPlus<T[]>

    An iterator that yields the chunks.

  • Returns an iterator yielding non-overlapping chunks of the iterator.

    If there aren't enough elements to fill a chunk, the extra elements will be omitted.

    If you want gaps between the chunks, consider using windows with the appropriate interval instead.

    Parameters

    • chunkSize: number

      The chunk size.

    Returns AsyncIterPlus<T[]>

    An iterator that yields the chunks.

  • collect(): Promise<T[]>
  • compare(other: AsyncIterable<T>): Promise<number>
  • Lexicographically compares this iterator with another.

    This function is short-circuiting, so it stops on the first inequality.

    Parameters

    • other: AsyncIterable<T>

      Iterable to compare to.

    Returns Promise<number>

    -1 if this is less than the other, 0 if it's equal, and 1 if it's greater than.

  • compareBy<O>(other: AsyncIterable<O>, cmp: (first: T, second: O) => PromiseOrValue<number>): Promise<number>
  • Lexicographically compares this iterator with another using a comparison function.

    This function is short-circuiting, so it stops on the first inequality.

    Type parameters

    • O

      The type of the other iterator.

    Parameters

    • other: AsyncIterable<O>

      Iterable to compare to.

    • cmp: (first: T, second: O) => PromiseOrValue<number>

      A function that should return a negative for less than, zero for equal to, and positive for greater than.

    Returns Promise<number>

    -1 if this is less than the other, 0 if it's equal, and 1 if it's greater than.

  • compareWith<K>(other: AsyncIterable<T>, key: (elem: T) => PromiseOrValue<K>): Promise<number>
  • Lexicographically compares this iterator with another using a key.

    This function is short-circuiting, so it stops on the first inequality.

    Type parameters

    • K

      The type of the key.

    Parameters

    • other: AsyncIterable<T>

      Iterable to compare to.

    • key: (elem: T) => PromiseOrValue<K>

      Function to generate a key to compare with from an element.

    Returns Promise<number>

    -1 if this is less than the other, 0 if it's equal, and 1 if it's greater than.

  • Concatenates one or more iterables to this iterator, creating an iterator that yields their elements in sequentual order.

    Parameters

    • Rest ...iters: AsyncIterable<T>[]

      The iterables to chain to this one.

    Returns AsyncIterPlus<T>

    The generated iterator.

  • count(): Promise<number>
  • Drops elements from the iterator from the end.

    This uses memory proportional to the number of elements dropped, as the iterator must look ahead and store elements to know that it has not reached the end.

    Parameters

    • n: number

      The number of elements to drop.

    Returns AsyncIterPlus<T>

    An iterator with the specified number of elements removed from the end.

  • equals(other: AsyncIterable<T>): Promise<boolean>
  • Checks if this iterator is equal to another.

    This function is short-circuiting, so it stops on the first inequality.

    Parameters

    • other: AsyncIterable<T>

      Iterable to compare to.

    Returns Promise<boolean>

    If the two iterators are equal.

  • equalsBy<O>(other: AsyncIterable<O>, cmp: (first: T, second: O) => PromiseOrValue<boolean>): Promise<boolean>
  • Checks if this iterator is equal to another using a comparison function.

    This function is short-circuiting, so it stops on the first inequality.

    Type parameters

    • O

      The type of the other iterable.

    Parameters

    • other: AsyncIterable<O>

      Iterable to compare to.

    • cmp: (first: T, second: O) => PromiseOrValue<boolean>

      A function that checks if elements are equal.

    Returns Promise<boolean>

    If the two iterators are equal.

  • equalsWith<K>(other: AsyncIterable<T>, key: (elem: T) => PromiseOrValue<K>): Promise<boolean>
  • Checks if this iterator is equal to another using a key.

    This function is short-circuiting, so it stops on the first inequality.

    Type parameters

    • K

      The type of the key.

    Parameters

    • other: AsyncIterable<T>

      Iterable to compare to.

    • key: (elem: T) => PromiseOrValue<K>

      Function to generate a key to compare with from an element.

    Returns Promise<boolean>

    If the two iterators are equal.

  • Checks if every element in the iterator matches a predicate.

    This function is short-circuiting, so if any element returns false, the function immediately returns false.

    Parameters

    Returns Promise<boolean>

    If every element satisfies the predicate.

  • Finds an element that satisfies a predicate.

    This function is short-circuiting, so it stops on the first match.

    Parameters

    Returns Promise<null | T>

    The element, or null if none was found.

  • findIndex(pred: (elem: T) => PromiseOrValue<boolean>): Promise<number>
  • Finds the index of an element that satisfies a predicate.

    If you want to find the value and the index, consider using enumerate then using find.

    This function is short-circuiting, so it stops on the first match.

    Parameters

    Returns Promise<number>

    The index, or -1 if none was found.

  • findMap<K>(func: (elem: T) => PromiseOrValue<null | K>): Promise<null | K>
  • Runs a function on every element and returns the first non-null element.

    This function is short-circuiting, so it stops on the first match.

    Type parameters

    • K

      The resulting type.

    Parameters

    Returns Promise<null | K>

    The element, or null if none was found.

  • flatMap<K>(func: (elem: T) => Iterable<K> | AsyncIterable<K> | Promise<Iterable<K> | AsyncIterable<K>>): AsyncIterPlus<K>
  • Maps then flattens an iterator.

    Type parameters

    • K

      The resulting type.

    Parameters

    • func: (elem: T) => Iterable<K> | AsyncIterable<K> | Promise<Iterable<K> | AsyncIterable<K>>

      The mapping function.

        • (elem: T): Iterable<K> | AsyncIterable<K> | Promise<Iterable<K> | AsyncIterable<K>>
        • Parameters

          • elem: T

          Returns Iterable<K> | AsyncIterable<K> | Promise<Iterable<K> | AsyncIterable<K>>

    Returns AsyncIterPlus<K>

    The generated iterator.

  • forEach(func: (elem: T) => unknown): Promise<void>
  • Runs a function on each element of an iterator.

    This is equivalent to running a for loop on the iterator. If you want to obtain the values, consider using .map(func).collect() instead.

    Parameters

    • func: (elem: T) => unknown

      The function to run.

        • (elem: T): unknown
        • Parameters

          • elem: T

          Returns unknown

    Returns Promise<void>

  • group<K>(key: (elem: T) => PromiseOrValue<K>): Promise<Record<K, T[]>>
  • hasCached(): boolean
  • Checks if there's a value cached from a previous peek.

    Will return true even if the cached value is the end of the iterator.

    Returns boolean

    If there's a value cached.

  • hasPrefix(other: AsyncIterable<T>): Promise<boolean>
  • Checks if this iterator is equal to another, while the second iterator still yields elements.

    This function is short-circuiting, so it stops on the first inequality.

    Parameters

    • other: AsyncIterable<T>

      Iterable to compare to.

    Returns Promise<boolean>

    If the first iterator starts with the second iterator.

  • hasPrefixBy<O>(other: AsyncIterable<O>, cmp: (first: T, second: O) => PromiseOrValue<boolean>): Promise<boolean>
  • Checks if this iterator is equal to another, while the second iterator still yields elements, using a comparison function.

    This function is short-circuiting, so it stops on the first inequality.

    Type parameters

    • O

      The type of the other iterable.

    Parameters

    • other: AsyncIterable<O>

      Iterable to compare to.

    • cmp: (first: T, second: O) => PromiseOrValue<boolean>

      A function that checks if elements are equal.

    Returns Promise<boolean>

    If the first iterator starts with the second iterator.

  • hasPrefixWith<K>(other: AsyncIterable<T>, key: (elem: T) => PromiseOrValue<K>): Promise<boolean>
  • Checks if this iterator is equal to another, while the second iterator still yields elements, with a key function.

    This function is short-circuiting, so it stops on the first inequality.

    Type parameters

    • K

      The type of the key.

    Parameters

    Returns Promise<boolean>

    If the first iterator starts with the second iterator.

  • headEquals(other: AsyncIterable<T>): Promise<boolean>
  • Checks if this iterator is equal to another, while they both yield elements.

    This function is short-circuiting, so it stops on the first inequality.

    However, if the first iterator terminates, a value will still be yielded from the second so that headEquals is commutative.

    Parameters

    • other: AsyncIterable<T>

      Iterable to compare to.

    Returns Promise<boolean>

    If the two iterators are equal.

  • headEqualsBy<O>(other: AsyncIterable<O>, cmp: (first: T, second: O) => PromiseOrValue<boolean>): Promise<boolean>
  • Checks if this iterator is equal to another, while they both yield elements, using a comparison function.

    This function is short-circuiting, so it stops on the first inequality.

    However, if the first iterator terminates, a value will still be yielded from the second so that headEquals is commutative.

    Type parameters

    • O

      The type of the other iterable.

    Parameters

    • other: AsyncIterable<O>

      Iterable to compare to.

    • cmp: (first: T, second: O) => PromiseOrValue<boolean>

      A function that checks if elements are equal.

    Returns Promise<boolean>

    If the two iterators are equal.

  • headEqualsWith<K>(other: AsyncIterable<T>, key: (elem: T) => PromiseOrValue<K>): Promise<boolean>
  • Checks if this iterator is equal to another, while they both yield elements, using a key.

    This function is short-circuiting, so it stops on the first inequality.

    However, if the first iterator terminates, a value will still be yielded from the second so that headEquals is commutative.

    Type parameters

    • K

      The type of the key.

    Parameters

    Returns Promise<boolean>

    If the two iterators are equal.

  • Lazily runs functions on an iterator, returning a new iterator with unmodified elements.

    This function is primarily used as a debugging tool to inspect elements in the middle of an iterator function chain.

    Parameters

    • func: (elem: T) => unknown

      The function to call.

        • (elem: T): unknown
        • Parameters

          • elem: T

          Returns unknown

    Returns AsyncIterPlus<T>

    The generated iterator.

  • Interleaves one or more iterables with this iterator.

    Parameters

    • Rest ...iters: AsyncIterable<T>[]

      The iterables to interleave with this one.

    Returns AsyncIterPlus<T>

    The interleaved iterator, yielding elements in the iterators in order.

  • isPartitioned(pred: (elem: T) => PromiseOrValue<boolean>): Promise<boolean>
  • Determines if an iterator is partitioned by a predicate (Items that return true come before items that return false).

    This function is short-circuiting, so it stops on the first non-partitioned element.

    Parameters

    Returns Promise<boolean>

    If the iterator is partitioned.

  • isSorted(): Promise<boolean>
  • Determines if an iterator is sorted increasingly.

    This function is short-circuiting, so it stops on the first non-sorted element.

    Returns Promise<boolean>

    If the iterator is sorted.

  • isSortedBy(cmp: (first: T, second: T) => PromiseOrValue<number>): Promise<boolean>
  • Determines if an iterator is sorted increasingly by a comparison function.

    This function is short-circuiting, so it stops on the first non-sorted element.

    Parameters

    • cmp: (first: T, second: T) => PromiseOrValue<number>

      A function that should return a negative for less than, zero for equal to, and positive for greater than.

    Returns Promise<boolean>

    If the iterator is sorted.

  • isSortedWith<K>(key: (elem: T) => PromiseOrValue<K>): Promise<boolean>
  • last(): Promise<null | T>
  • Finds the last element in an iterator.

    Returns Promise<null | T>

    The last element of the iterator, or null if the iterator is empty.

  • Lazily maps an iterator, creating a new iterator where each element has been modified by a function.

    If you want to immediately run a function on all elements of the iterator, use forEach instead.

    Type parameters

    • K

      The resulting type.

    Parameters

    Returns AsyncIterPlus<K>

    The generated iterator.

  • Runs a function for every element of the iterator, keeping track of an accumulator.

    Type parameters

    • A

      The type of the accumulator.

    • V

      The resulting type.

    Parameters

    • func: (accum: A, elem: T) => PromiseOrValue<[A, V]>

      The mapping function.

    • initializer: A

      The initial accumulator.

    Returns AsyncIterPlus<V>

    The mapped iterator.

  • max(overwrite?: boolean): Promise<null | T>
  • Finds the maximum value of an iterator.

    Parameters

    • overwrite: boolean = false

      If true, elements will be counted as the new maximum if they are equal to the maximum. Defaults to false.

    Returns Promise<null | T>

    The maximum element, or null if the iterator is empty.

  • maxBy(cmp: (first: T, second: T) => PromiseOrValue<number>, overwrite?: boolean): Promise<null | T>
  • Finds the maximum value of an iterator with a comparison function.

    Parameters

    • cmp: (first: T, second: T) => PromiseOrValue<number>

      A function that should return a negative for less than, zero for equal to, and positive for greater than.

    • overwrite: boolean = false

      If true, elements will be counted as the new maximum if they are equal to the maximum. Defaults to false.

    Returns Promise<null | T>

    The maximum element, or null if the iterator is empty.

  • maxWith<K>(key: (elem: T) => PromiseOrValue<K>, overwrite?: boolean): Promise<null | T>
  • Finds the maximum value of an iterator with a key.

    Type parameters

    • K

      The type of the key.

    Parameters

    • key: (elem: T) => PromiseOrValue<K>

      The key function.

    • overwrite: boolean = false

      If true, elements will be counted as the new maximum if they are equal to the maximum. Defaults to false.

    Returns Promise<null | T>

    The maximum element, or null if the iterator is empty.

  • min(overwrite?: boolean): Promise<null | T>
  • Finds the minimum value of an iterator.

    Parameters

    • overwrite: boolean = false

      If true, elements will be counted as the new minimum if they are equal to the minimum. Defaults to false.

    Returns Promise<null | T>

    The minimum element, or null if the iterator is empty.

  • minBy(cmp: (first: T, second: T) => PromiseOrValue<number>, overwrite?: boolean): Promise<null | T>
  • Finds the minimum value of an iterator with a comparison function.

    Parameters

    • cmp: (first: T, second: T) => PromiseOrValue<number>

      A function that should return a negative for less than, zero for equal to, and positive for greater than.

    • overwrite: boolean = false

      If true, elements will be counted as the new minimum if they are equal to the minimum. Defaults to false.

    Returns Promise<null | T>

    The minimum element, or null if the iterator is empty.

  • minWith<K>(key: (elem: T) => PromiseOrValue<K>, overwrite?: boolean): Promise<null | T>
  • Finds the minimum value of an iterator with a key.

    Type parameters

    • K

      The type of the key.

    Parameters

    • key: (elem: T) => PromiseOrValue<K>

      The key function.

    • overwrite: boolean = false

      If true, elements will be counted as the new minimum if they are equal to the minimum. Defaults to false.

    Returns Promise<null | T>

    The minimum element, or null if the iterator is empty.

  • next(): Promise<IteratorResult<T, any>>
  • nextVal(): Promise<null | T>
  • nth(n: number): Promise<null | T>
  • Finds the nth element in an iterator.

    Parameters

    • n: number

      The number element to get.

    Returns Promise<null | T>

    The nth element of the iterator, or null if the iterator is too short.

  • Removes duplicates from an iterator, including non-consecutive ones, with a comparison function.

    Unlike nubWith and nub, this does not use a set, so it is significantly slower.

    Parameters

    Returns AsyncIterPlus<T>

    The nubbed iterator.

  • partition(pred: (elem: T) => PromiseOrValue<boolean>): Promise<[T[], T[]]>
  • peek(): Promise<IteratorResult<T, any>>
  • Peeks the next element in the iterator and does not consume it.

    Returns Promise<IteratorResult<T, any>>

    The next element as an iterator result.

  • peekVal(): Promise<null | T>
  • Peeks the next element in the iterator and does not consume it.

    Nullable version of peek.

    Returns Promise<null | T>

    The next element, or null if the iterator is finished.

  • product(empty?: number): Promise<number>
  • product(empty: bigint): Promise<bigint>
  • Returns the product of all elements in the iterator.

    Parameters

    • Optional empty: number

      The default value for an empty iterator. Defaults to 1.

    Returns Promise<number>

    The product.

  • Returns the product of all elements in the iterator.

    Parameters

    • empty: bigint

      The default value for an empty iterator. For bigint iterators it's advised to explicitly set this to 1n or another bigint.

    Returns Promise<bigint>

    The product.

  • reduce<A>(func: (accum: A, elem: T) => PromiseOrValue<A>, initializer: A): Promise<A>
  • reduce(func: (accum: T, elem: T) => PromiseOrValue<T>): Promise<T>
  • Runs a function for every element of the iterator, keeping track of an accumulator.

    Type parameters

    • A

      The type of the accumulator.

    Parameters

    Returns Promise<A>

    The final accumulator.

  • Runs a function for every element of the iterator, keeping track of an accumulator.

    Uses the first element as the initial accumulator, and it will be skipped over in the reduction.

    throws

    If the iterator is empty, then an error will be thrown.

    Parameters

    Returns Promise<T>

    The final accumulator.

  • Creates an iterator that repeats the contents of the current iterator a certain number of times.

    Parameters

    • n: number

      The number of times to repeat.

    Returns AsyncIterPlus<T>

    An iterator that repeats itself n times.

  • Consumes the iterator and reverses it.

    This has to immediately resolve every element in the iterator, so it is equivalent to collecting to an array and revsersing the array, so it is very inefficient on memory and should be avoided.

    Returns Promise<IterPlus<T>>

    The reversed iterator.

  • Creates an iterator that's rotated left a certain amount, so elements at the start end up at the end.

    This does not handle negative numbers due to right rotation being significantly slower. If you want negatives, please do the checks yourself and use rotateRight when appropriate.

    throws

    A RangeError when the amount is negative.

    Parameters

    • amount: number

      Amount to rotate by.

    Returns AsyncIterPlus<T>

    The rotated iterator.

  • Creates an iterator that's rotated right a certain amount, so elements at the end end up at the start.

    Due to the one-directional nature of iterators, this is not lazy and therefore much slower than rotateLeft.

    This does not handle negative numbers to be consistent with rotateLeft. If you want negatives, please do the checks yourself and use rotateRight when appropriate.

    throws

    A RangeError when the amount is negative.

    Parameters

    • amount: number

      Amount to rotate by.

    Returns AsyncIterPlus<T>

    The rotated iterator.

  • Runs a function for every element of the iterator, keeping track of an accumulator.

    Type parameters

    • A

      The type of the accumulator.

    Parameters

    Returns AsyncIterPlus<A>

    The iterator containing all intermediate accumulators.

  • Runs a function for every element of the iterator, keeping track of an accumulator.

    Uses the first element as the initial accumulator, and it will be skipped over in the scan.

    throws

    If the iterator is empty, then an error will be thrown.

    Parameters

    Returns AsyncIterPlus<T>

    The iterator containing all intermediate accumulators.

  • Checks if some element in the iterator matches a predicate.

    This function is short-circuiting, so if any element returns true, the function immediately returns true.

    Parameters

    Returns Promise<boolean>

    If some element satisfies the predicate.

  • Splits an iterator on an element, including the matched element as the last element of the chunk.

    Unlike the exclusive split, this does not create an empty chunk on the end when ending with the matched element.

    Parameters

    • elem: PromiseOrValue<T>
    • limit: number = Infinity

      The maximum number of chunks to make.

    Returns AsyncIterPlus<T[]>

    The iterator with the split chunks.

  • Splits an iterator on a predicate, including the matched element as the last element of the chunk.

    Unlike the exclusive split, this does not create an empty chunk on the end when ending with the matched element.

    Parameters

    • pred: (elem: T) => PromiseOrValue<boolean>

      The predicate to split with.

    • limit: number = Infinity

      The maximum number of chunks to make.

    Returns AsyncIterPlus<T[]>

    The iterator with the split chunks.

  • Steps through an iterator by a certain amount, starting from the first.

    A step of 2 would yield the first element, then the third, then the fifth, and so on.

    Parameters

    • step: number

      The step size.

    Returns AsyncIterPlus<T>

    An iterator that advances by the given step size.

  • sum(empty?: number): Promise<number>
  • sum(empty: bigint): Promise<bigint>
  • sum(empty: string): Promise<string>
  • Returns the sum of all elements in the iterator.

    Parameters

    • Optional empty: number

      The default value for an empty iterator. Defaults to 0.

    Returns Promise<number>

    The sum.

  • Returns the sum of all elements in the iterator.

    Parameters

    • empty: bigint

      The default value for an empty iterator. For bigint iterators it's advised to explicitly set this to 0n or another bigint.

    Returns Promise<bigint>

    The sum.

  • Returns the sum of all elements in the iterator.

    Parameters

    • empty: string

      The default value for an empty iterator. For string iterators it's advised to explicitly set this to "" or another string.

    Returns Promise<string>

    The sum.

  • tally(): Promise<Record<string, number>>
  • Tallies elements of an iterator together.

    Returns Promise<Record<string, number>>

    An object mapping keys to the number of times they appeared.

  • tallyWith<K>(key: (elem: T) => PromiseOrValue<K>): Promise<Record<K, number>>
  • Tallies elements of an iterator together with a key function.

    Type parameters

    • K: string | number | symbol

      The type of the key.

    Parameters

    Returns Promise<Record<K, number>>

    An object mapping keys to the number of times they appeared.

  • Splits an iterator into multiple, where advancing one iterator does not advance the others.

    Functions by storing old values and removing when no longer needed, so only tee as many iterators as you need in order for memory to be cleaned properly.

    The original iterator will still be advanced, so only used the iterators returned by tee.

    Parameters

    • count: number = 2

      The number of iterators to split into.

    Returns AsyncIterPlus<T>[]

    An array of length count with separate iterators.

  • toArray(): Promise<T[]>
  • toMap<K, V>(duplicate: "overwrite" | "maintain" | "error"): Promise<Map<K, V>>
  • Converts an iterator of key-value pairs into a map.

    throws

    A RangeError if duplicate is "error" and a duplicate key is encountered.

    Type parameters

    • K

      The key type.

    • V

      The value type.

    Parameters

    • duplicate: "overwrite" | "maintain" | "error"

      How to handle duplicate keys. "overwrite" replaces values with the new value. "maintain" maintains the old value. "error" throws an error. Defaults to "overwrite".

    Returns Promise<Map<K, V>>

    The generated map.

  • toObject<K, V>(duplicate: "overwrite" | "maintain" | "error"): Promise<{}>
  • Converts an iterator of key-value pairs into an object.

    throws

    A RangeError if duplicate is "error" and a duplicate key is encountered.

    Type parameters

    • K

      The key type.

    • V

      The value type.

    Parameters

    • duplicate: "overwrite" | "maintain" | "error"

      How to handle duplicate keys. "overwrite" replaces values with the new value. "maintain" maintains the old value. "error" throws an error. Defaults to "overwrite".

    Returns Promise<{}>

    The generated object.

  • toSet(): Promise<Set<T>>
  • unzip<K>(): Promise<ArrayMap<K>>
  • "Unzips" an iterator of tuples into a tuple of arrays.

    Type parameters

    • K: unknown[]

      The tuple type.

    Returns Promise<ArrayMap<K>>

    A tuple with the individual elements.

  • windows(windowSize: number, interval?: number): AsyncIterPlus<T[]>
  • Returns an iterator yielding overlapping windows of the iterator.

    If there aren't enough elements to fill a window, no windows will be yielded.

    Parameters

    • windowSize: number

      The window size.

    • interval: number = 1

      The increment between the starts of windows. Defaults to 1.

    Returns AsyncIterPlus<T[]>

    An iterator that yields the windows.

  • zip<K>(...iters: AsyncIterableMap<K>): AsyncIterPlus<[T, ...K[]]>
  • Zips one or more iterables with this iterator.

    Type parameters

    • K: unknown[]

      The types of the other iterables.

    Parameters

    • Rest ...iters: AsyncIterableMap<K>

      The iterables to zip with this one.

    Returns AsyncIterPlus<[T, ...K[]]>

    The generated iterator.

  • Zips one or more iterables with this iterator using a function.

    Stops once any one of the iterators stop.

    Type parameters

    • K: unknown[]

      The types of the other iterables.

    • R

      The resulting value.

    Parameters

    • func: (...args: [T, ...K[]]) => PromiseOrValue<R>

      The function to use when zipping.

    • Rest ...iters: AsyncIterableMap<K>

      The iterables to zip with this one.

    Returns AsyncIterPlus<R>

    The generated iterator.

  • Generates an iterator that iterates through lexicographically sorted combinations without repetition of a dataset.

    Type parameters

    • T

      The item type of the iterator.

    Parameters

    • data: T[]

      The data to generate combinations from.

    • count: number = data.length

      The number of elements in each combination.

    Returns AsyncIterPlus<T[]>

    The generated iterator.

  • combinationsWithRepetition<T>(data: T[], count?: number): AsyncIterPlus<T[]>
  • Generates an iterator that iterates through lexicographically sorted combinations with repetition of a dataset.

    Type parameters

    • T

      The item type of the iterator.

    Parameters

    • data: T[]

      The data to generate combinations from.

    • count: number = data.length

      The number of elements in each combination.

    Returns AsyncIterPlus<T[]>

    The generated iterator.

  • Generates an iterator that cycles through an iterable.

    While this does work on infinite iterators, it should be avoided as it stores all elements, leading to an ever-growing memory usage.

    Type parameters

    • T

      The item type of the iterator.

    Parameters

    • data: AsyncIterable<T>

      The iterable to cycle through.

    Returns AsyncIterPlus<T>

    The generated iterator.

  • Generates an iterator that iterates through lexicographically sorted permutations without repetition of a dataset.

    Type parameters

    • T

      The item type of the iterator.

    Parameters

    • data: T[]

      The data to generate permutations from.

    • count: number = data.length

      The number of elements in each permutations.

    Returns AsyncIterPlus<T[]>

    The generated iterator.

  • permutationsWithRepetition<T>(data: T[], count?: number): AsyncIterPlus<T[]>
  • Generates an iterator that iterates through lexicographically sorted permutations with repetition of a dataset.

    Type parameters

    • T

      The item type of the iterator.

    Parameters

    • data: T[]

      The data to generate permutations from.

    • count: number = data.length

      The number of elements in each permutations.

    Returns AsyncIterPlus<T[]>

    The generated iterator.

  • Generates an iterator that iterates through the lexicographically sorted powerset of a dataset.

    Type parameters

    • T

      The item type of the iterator.

    Parameters

    • data: T[]

      The data to get the powerset of.

    Returns AsyncIterPlus<T[]>

    The generated iterator.

  • Generates an iterator that generates a lexicographically sorted cartesian product.

    Type parameters

    • T: unknown[]

      The item type of the iterator.

    Parameters

    • Rest ...data: ArrayMap<T>

      The iterators to take the product of.

    Returns AsyncIterPlus<T>

    The generated iterator.

Generated using TypeDoc