@mirei/ts-collections
    Preparing search index...

    Interface IOrderedAsyncEnumerable<TElement>

    interface IOrderedAsyncEnumerable<TElement> {
        "[asyncIterator]"(): AsyncIterator<TElement, any, any>;
        aggregate<TAccumulate = TElement, TResult = TAccumulate>(
            accumulator: Accumulator<TElement, TAccumulate>,
            seed?: TAccumulate,
            resultSelector?: Selector<TAccumulate, TResult>,
        ): Promise<TAccumulate | TResult>;
        aggregateBy<TKey, TAccumulate = TElement>(
            keySelector: Selector<TElement, TKey>,
            seedSelector: TAccumulate | Selector<TKey, TAccumulate>,
            accumulator: Accumulator<TElement, TAccumulate>,
            keyComparator?: EqualityComparator<TKey, TKey>,
        ): IAsyncEnumerable<KeyValuePair<TKey, TAccumulate>>;
        all(predicate: Predicate<TElement>): Promise<boolean>;
        any(predicate?: Predicate<TElement>): Promise<boolean>;
        append(element: TElement): IAsyncEnumerable<TElement>;
        atLeast(count: number, predicate?: Predicate<TElement>): Promise<boolean>;
        atMost(count: number, predicate?: Predicate<TElement>): Promise<boolean>;
        average(selector?: Selector<TElement, number>): Promise<number>;
        cartesian<TSecond>(
            iterable: AsyncIterable<TSecond>,
        ): IAsyncEnumerable<[TElement, TSecond]>;
        cast<TResult>(): IAsyncEnumerable<TResult>;
        chunk(size: number): IAsyncEnumerable<IEnumerable<TElement>>;
        combinations(size?: number): IAsyncEnumerable<IEnumerable<TElement>>;
        compact(): IAsyncEnumerable<NonNullable<TElement>>;
        concat(other: AsyncIterable<TElement>): IAsyncEnumerable<TElement>;
        contains(
            element: TElement,
            comparator?: EqualityComparator<TElement, TElement>,
        ): Promise<boolean>;
        correlation<TSecond>(
            iterable: AsyncIterable<TSecond>,
            selector?: Selector<TElement, number>,
            otherSelector?: Selector<TSecond, number>,
        ): Promise<number>;
        correlationBy(
            leftSelector: Selector<TElement, number>,
            rightSelector: Selector<TElement, number>,
        ): Promise<number>;
        count(predicate?: Predicate<TElement>): Promise<number>;
        countBy<TKey>(
            keySelector: Selector<TElement, TKey>,
            comparator?: EqualityComparator<TKey, TKey>,
        ): IAsyncEnumerable<KeyValuePair<TKey, number>>;
        covariance<TSecond>(
            iterable: AsyncIterable<TSecond>,
            selector?: Selector<TElement, number>,
            otherSelector?: Selector<TSecond, number>,
            sample?: boolean,
        ): Promise<number>;
        covarianceBy(
            leftSelector: Selector<TElement, number>,
            rightSelector: Selector<TElement, number>,
            sample?: boolean,
        ): Promise<number>;
        cycle(count?: number): IAsyncEnumerable<TElement>;
        defaultIfEmpty(
            defaultValue?: TElement | null,
        ): IAsyncEnumerable<TElement | null>;
        disjoint<TSecond>(
            iterable: AsyncIterable<TSecond>,
            comparator?: EqualityComparator<TElement | TSecond, TElement | TSecond>,
        ): Promise<boolean>;
        disjointBy<TSecond, TKey, TSecondKey>(
            iterable: AsyncIterable<TSecond>,
            keySelector: Selector<TElement, TKey>,
            otherKeySelector: Selector<TSecond, TSecondKey>,
            keyComparator?: EqualityComparator<TKey | TSecondKey, TKey | TSecondKey>,
        ): Promise<boolean>;
        distinct(
            keyComparator?: EqualityComparator<TElement, TElement>,
        ): IAsyncEnumerable<TElement>;
        distinctBy<TKey>(
            keySelector: Selector<TElement, TKey>,
            keyComparator?: EqualityComparator<TKey, TKey>,
        ): IAsyncEnumerable<TElement>;
        distinctUntilChanged(
            comparator?: EqualityComparator<TElement, TElement>,
        ): IAsyncEnumerable<TElement>;
        distinctUntilChangedBy<TKey>(
            keySelector: Selector<TElement, TKey>,
            keyComparator?: EqualityComparator<TKey, TKey>,
        ): IAsyncEnumerable<TElement>;
        elementAt(index: number): Promise<TElement>;
        elementAtOrDefault(index: number): Promise<TElement | null>;
        exactly(count: number, predicate?: Predicate<TElement>): Promise<boolean>;
        except(
            enumerable: AsyncIterable<TElement>,
            comparator?:
                | EqualityComparator<TElement, TElement>
                | OrderComparator<TElement, TElement>,
        ): IAsyncEnumerable<TElement>;
        exceptBy<TKey>(
            enumerable: AsyncIterable<TElement>,
            keySelector: Selector<TElement, TKey>,
            comparator?: EqualityComparator<TKey, TKey> | OrderComparator<TKey, TKey>,
        ): IAsyncEnumerable<TElement>;
        first<TFiltered>(
            predicate: TypePredicate<TElement, TFiltered>,
        ): Promise<TFiltered>;
        first(predicate?: Predicate<TElement>): Promise<TElement>;
        firstOrDefault<TFiltered>(
            predicate: TypePredicate<TElement, TFiltered>,
        ): Promise<TFiltered | null>;
        firstOrDefault(predicate?: Predicate<TElement>): Promise<TElement | null>;
        forEach(action: IndexedAction<TElement>): Promise<void>;
        groupBy<TKey>(
            keySelector: Selector<TElement, TKey>,
            keyComparator?: EqualityComparator<TKey, TKey>,
        ): IAsyncEnumerable<IGroup<TKey, TElement>>;
        groupJoin<TInner, TKey, TResult>(
            inner: IAsyncEnumerable<TInner>,
            outerKeySelector: Selector<TElement, TKey>,
            innerKeySelector: Selector<TInner, TKey>,
            resultSelector: JoinSelector<TElement, IEnumerable<TInner>, TResult>,
            keyComparator?: EqualityComparator<TKey, TKey>,
        ): IAsyncEnumerable<TResult>;
        index(): IAsyncEnumerable<[number, TElement]>;
        interleave<TSecond>(
            iterable: AsyncIterable<TSecond>,
        ): IAsyncEnumerable<TElement | TSecond>;
        intersect(
            enumerable: AsyncIterable<TElement>,
            comparator?:
                | EqualityComparator<TElement, TElement>
                | OrderComparator<TElement, TElement>,
        ): IAsyncEnumerable<TElement>;
        intersectBy<TKey>(
            enumerable: AsyncIterable<TElement>,
            keySelector: Selector<TElement, TKey>,
            comparator?: EqualityComparator<TKey, TKey> | OrderComparator<TKey, TKey>,
        ): IAsyncEnumerable<TElement>;
        intersperse<TSeparator = TElement>(
            separator: TSeparator,
        ): IAsyncEnumerable<TElement | TSeparator>;
        join<TInner, TKey, TResult>(
            inner: IAsyncEnumerable<TInner>,
            outerKeySelector: Selector<TElement, TKey>,
            innerKeySelector: Selector<TInner, TKey>,
            resultSelector: JoinSelector<TElement, TInner, TResult>,
            keyComparator?: EqualityComparator<TKey, TKey>,
        ): IAsyncEnumerable<TResult>;
        last<TFiltered>(
            predicate: TypePredicate<TElement, TFiltered>,
        ): Promise<TFiltered>;
        last(predicate?: Predicate<TElement>): Promise<TElement>;
        lastOrDefault<TFiltered>(
            predicate: TypePredicate<TElement, TFiltered>,
        ): Promise<TFiltered | null>;
        lastOrDefault(predicate?: Predicate<TElement>): Promise<TElement | null>;
        leftJoin<TInner, TKey, TResult>(
            inner: IAsyncEnumerable<TInner>,
            outerKeySelector: Selector<TElement, TKey>,
            innerKeySelector: Selector<TInner, TKey>,
            resultSelector: JoinSelector<TElement, TInner, TResult>,
            keyComparator?: EqualityComparator<TKey, TKey>,
        ): IAsyncEnumerable<TResult>;
        max(selector?: Selector<TElement, number>): Promise<number>;
        maxBy<TKey>(
            keySelector: Selector<TElement, TKey>,
            comparator?: OrderComparator<TKey, TKey>,
        ): Promise<TElement>;
        median(
            selector?: Selector<TElement, number>,
            tie?: MedianTieStrategy,
        ): Promise<number>;
        min(selector?: Selector<TElement, number>): Promise<number>;
        minBy<TKey>(
            keySelector: Selector<TElement, TKey>,
            comparator?: OrderComparator<TKey, TKey>,
        ): Promise<TElement>;
        mode<TKey>(keySelector?: Selector<TElement, TKey>): Promise<TElement>;
        modeOrDefault<TKey>(
            keySelector?: Selector<TElement, TKey>,
        ): Promise<TElement | null>;
        multimode<TKey>(
            keySelector?: Selector<TElement, TKey>,
        ): IAsyncEnumerable<TElement>;
        none(predicate?: Predicate<TElement>): Promise<boolean>;
        ofType<TResult extends ObjectType>(
            type: TResult,
        ): IAsyncEnumerable<InferredType<TResult>>;
        order(
            comparator?: OrderComparator<TElement, TElement>,
        ): IOrderedAsyncEnumerable<TElement>;
        orderBy<TKey>(
            keySelector: Selector<TElement, TKey>,
            comparator?: OrderComparator<TKey, TKey>,
        ): IOrderedAsyncEnumerable<TElement>;
        orderByDescending<TKey>(
            keySelector: Selector<TElement, TKey>,
            comparator?: OrderComparator<TKey, TKey>,
        ): IOrderedAsyncEnumerable<TElement>;
        orderDescending(
            comparator?: OrderComparator<TElement, TElement>,
        ): IOrderedAsyncEnumerable<TElement>;
        pairwise(
            resultSelector: PairwiseSelector<TElement, TElement>,
        ): IAsyncEnumerable<[TElement, TElement]>;
        partition<TFiltered>(
            predicate: TypePredicate<TElement, TFiltered>,
        ): Promise<
            [IEnumerable<TFiltered>, IEnumerable<Exclude<TElement, TFiltered>>],
        >;
        partition(
            predicate: Predicate<TElement>,
        ): Promise<[IEnumerable<TElement>, IEnumerable<TElement>]>;
        percentile(
            percent: number,
            selector?: Selector<TElement, number>,
            strategy?: PercentileStrategy,
        ): Promise<number>;
        permutations(size?: number): IAsyncEnumerable<IEnumerable<TElement>>;
        pipe<TResult>(
            operator: AsyncPipeOperator<TElement, TResult>,
        ): Promise<TResult>;
        prepend(element: TElement): IAsyncEnumerable<TElement>;
        product(selector?: Selector<TElement, number>): Promise<number>;
        reverse(): IAsyncEnumerable<TElement>;
        rightJoin<TInner, TKey, TResult>(
            inner: IAsyncEnumerable<TInner>,
            outerKeySelector: Selector<TElement, TKey>,
            innerKeySelector: Selector<TInner, TKey>,
            resultSelector: JoinSelector<TElement | null, TInner, TResult>,
            keyComparator?: EqualityComparator<TKey, TKey>,
        ): IAsyncEnumerable<TResult>;
        rotate(shift: number): IAsyncEnumerable<TElement>;
        scan<TAccumulate = TElement>(
            accumulator: Accumulator<TElement, TAccumulate>,
            seed?: TAccumulate,
        ): IAsyncEnumerable<TAccumulate>;
        select<TResult>(
            selector: IndexedSelector<TElement, TResult>,
        ): IAsyncEnumerable<TResult>;
        selectMany<TResult>(
            selector: IndexedSelector<TElement, Iterable<TResult, any, any>>,
        ): IAsyncEnumerable<TResult>;
        sequenceEqual(
            enumerable: AsyncIterable<TElement>,
            comparator?: EqualityComparator<TElement, TElement>,
        ): Promise<boolean>;
        shuffle(): IAsyncEnumerable<TElement>;
        single<TFiltered>(
            predicate: TypePredicate<TElement, TFiltered>,
        ): Promise<TFiltered>;
        single(predicate?: Predicate<TElement>): Promise<TElement>;
        singleOrDefault<TFiltered>(
            predicate: TypePredicate<TElement, TFiltered>,
        ): Promise<TFiltered | null>;
        singleOrDefault(predicate?: Predicate<TElement>): Promise<TElement | null>;
        skip(count: number): IAsyncEnumerable<TElement>;
        skipLast(count: number): IAsyncEnumerable<TElement>;
        skipUntil<TFiltered>(
            predicate: IndexedTypePredicate<TElement, TFiltered>,
        ): IAsyncEnumerable<TFiltered>;
        skipUntil(
            predicate: IndexedPredicate<TElement>,
        ): IAsyncEnumerable<TElement>;
        skipWhile(
            predicate: IndexedPredicate<TElement>,
        ): IAsyncEnumerable<TElement>;
        span<TFiltered>(
            predicate: TypePredicate<TElement, TFiltered>,
        ): Promise<[IEnumerable<TFiltered>, IEnumerable<TElement>]>;
        span(
            predicate: Predicate<TElement>,
        ): Promise<[IEnumerable<TElement>, IEnumerable<TElement>]>;
        standardDeviation(
            selector?: Selector<TElement, number>,
            sample?: boolean,
        ): Promise<number>;
        step(step: number): IAsyncEnumerable<TElement>;
        sum(selector?: Selector<TElement, number>): Promise<number>;
        take(count: number): IAsyncEnumerable<TElement>;
        takeLast(count: number): IAsyncEnumerable<TElement>;
        takeUntil<TFiltered>(
            predicate: IndexedTypePredicate<TElement, TFiltered>,
        ): IAsyncEnumerable<TFiltered>;
        takeUntil(
            predicate: IndexedPredicate<TElement>,
        ): IAsyncEnumerable<TElement>;
        takeWhile<TFiltered>(
            predicate: IndexedTypePredicate<TElement, TFiltered>,
        ): IAsyncEnumerable<TFiltered>;
        takeWhile(
            predicate: IndexedPredicate<TElement>,
        ): IAsyncEnumerable<TElement>;
        tap(action: IndexedAction<TElement>): IAsyncEnumerable<TElement>;
        thenBy<TKey>(
            keySelector: Selector<TElement, TKey>,
            comparator?: OrderComparator<TKey, TKey>,
        ): IOrderedAsyncEnumerable<TElement>;
        thenByDescending<TKey>(
            keySelector: Selector<TElement, TKey>,
            comparator?: OrderComparator<TKey, TKey>,
        ): IOrderedAsyncEnumerable<TElement>;
        toArray(): Promise<TElement[]>;
        toCircularLinkedList(
            comparator?: EqualityComparator<TElement, TElement>,
        ): Promise<CircularLinkedList<TElement>>;
        toCircularQueue(
            comparator?: EqualityComparator<TElement, TElement>,
        ): Promise<CircularQueue<TElement>>;
        toCircularQueue(
            capacity: number,
            comparator?: EqualityComparator<TElement, TElement>,
        ): Promise<CircularQueue<TElement>>;
        toDictionary<TKey, TValue>(
            keySelector: Selector<TElement, TKey>,
            valueSelector: Selector<TElement, TValue>,
            valueComparator?: EqualityComparator<TValue, TValue>,
        ): Promise<Dictionary<TKey, TValue>>;
        toEnumerableSet(): Promise<EnumerableSet<TElement>>;
        toImmutableCircularQueue(
            comparator?: EqualityComparator<TElement, TElement>,
        ): Promise<ImmutableCircularQueue<TElement>>;
        toImmutableCircularQueue(
            capacity: number,
            comparator?: EqualityComparator<TElement, TElement>,
        ): Promise<ImmutableCircularQueue<TElement>>;
        toImmutableDictionary<TKey, TValue>(
            keySelector: Selector<TElement, TKey>,
            valueSelector: Selector<TElement, TValue>,
            valueComparator?: EqualityComparator<TValue, TValue>,
        ): Promise<ImmutableDictionary<TKey, TValue>>;
        toImmutableList(
            comparator?: EqualityComparator<TElement, TElement>,
        ): Promise<ImmutableList<TElement>>;
        toImmutablePriorityQueue(
            comparator?: OrderComparator<TElement, TElement>,
        ): Promise<ImmutablePriorityQueue<TElement>>;
        toImmutableQueue(
            comparator?: EqualityComparator<TElement, TElement>,
        ): Promise<ImmutableQueue<TElement>>;
        toImmutableSet(): Promise<ImmutableSet<TElement>>;
        toImmutableSortedDictionary<TKey, TValue>(
            keySelector: Selector<TElement, TKey>,
            valueSelector: Selector<TElement, TValue>,
            keyComparator?: OrderComparator<TKey, TKey>,
            valueComparator?: EqualityComparator<TValue, TValue>,
        ): Promise<ImmutableSortedDictionary<TKey, TValue>>;
        toImmutableSortedSet(
            comparator?: OrderComparator<TElement, TElement>,
        ): Promise<ImmutableSortedSet<TElement>>;
        toImmutableStack(
            comparator?: EqualityComparator<TElement, TElement>,
        ): Promise<ImmutableStack<TElement>>;
        toLinkedList(
            comparator?: EqualityComparator<TElement, TElement>,
        ): Promise<LinkedList<TElement>>;
        toList(
            comparator?: EqualityComparator<TElement, TElement>,
        ): Promise<List<TElement>>;
        toLookup<TKey, TValue>(
            keySelector: Selector<TElement, TKey>,
            valueSelector: Selector<TElement, TValue>,
            keyComparator?: OrderComparator<TKey, TKey>,
        ): Promise<ILookup<TKey, TValue>>;
        toMap<TKey, TValue>(
            keySelector: Selector<TElement, TKey>,
            valueSelector: Selector<TElement, TValue>,
        ): Promise<Map<TKey, TValue>>;
        toObject<TKey extends PropertyKey, TValue>(
            keySelector: Selector<TElement, TKey>,
            valueSelector: Selector<TElement, TValue>,
        ): Promise<Record<TKey, TValue>>;
        toPriorityQueue(
            comparator?: OrderComparator<TElement, TElement>,
        ): Promise<PriorityQueue<TElement>>;
        toQueue(
            comparator?: EqualityComparator<TElement, TElement>,
        ): Promise<Queue<TElement>>;
        toSet(): Promise<Set<TElement>>;
        toSortedDictionary<TKey, TValue>(
            keySelector: Selector<TElement, TKey>,
            valueSelector: Selector<TElement, TValue>,
            keyComparator?: OrderComparator<TKey, TKey>,
            valueComparator?: EqualityComparator<TValue, TValue>,
        ): Promise<SortedDictionary<TKey, TValue>>;
        toSortedSet(
            comparator?: OrderComparator<TElement, TElement>,
        ): Promise<SortedSet<TElement>>;
        toStack(
            comparator?: EqualityComparator<TElement, TElement>,
        ): Promise<Stack<TElement>>;
        union(
            enumerable: AsyncIterable<TElement>,
            comparator?: EqualityComparator<TElement, TElement>,
        ): IAsyncEnumerable<TElement>;
        unionBy<TKey>(
            enumerable: AsyncIterable<TElement>,
            keySelector: Selector<TElement, TKey>,
            comparator?: EqualityComparator<TKey, TKey>,
        ): IAsyncEnumerable<TElement>;
        variance(
            selector?: Selector<TElement, number>,
            sample?: boolean,
        ): Promise<number>;
        where<TFiltered>(
            predicate: IndexedTypePredicate<TElement, TFiltered>,
        ): IAsyncEnumerable<TFiltered>;
        where(predicate: IndexedPredicate<TElement>): IAsyncEnumerable<TElement>;
        windows(size: number): IAsyncEnumerable<IEnumerable<TElement>>;
        zip<TSecond>(
            iterable: AsyncIterable<TSecond>,
        ): IAsyncEnumerable<[TElement, TSecond]>;
        zip<TSecond, TResult = [TElement, TSecond]>(
            iterable: AsyncIterable<TSecond>,
            zipper: Zipper<TElement, TSecond, TResult>,
        ): IAsyncEnumerable<TResult>;
        zipMany<TIterable extends readonly AsyncIterable<unknown, any, any>[]>(
            ...iterables: [...TIterable[]],
        ): IAsyncEnumerable<[TElement, ...UnpackAsyncIterableTuple<TIterable>[]]>;
        zipMany<
            TIterable extends readonly AsyncIterable<unknown, any, any>[],
            TResult,
        >(
            ...iterablesAndZipper: [
                ...TIterable[],
                ZipManyZipper<
                    [TElement, ...UnpackAsyncIterableTuple<TIterable>[]],
                    TResult,
                >,
            ],
        ): IAsyncEnumerable<TResult>;
    }

    Type Parameters

    • TElement

    Hierarchy (View Summary)

    Implemented by

    Index

    Methods

    • Asynchronously combines the elements of the sequence by applying an accumulator to each element and optionally projecting the final result.

      Type Parameters

      • TAccumulate = TElement

        Type of the intermediate accumulator. Defaults to TElement when no seed is provided.

      • TResult = TAccumulate

        Type returned when a resultSelector is supplied.

      Parameters

      • accumulator: Accumulator<TElement, TAccumulate>

        Function that merges the running accumulator with the next element.

      • Optionalseed: TAccumulate

        Optional initial accumulator value. When omitted, the first element is used as the starting accumulator.

      • OptionalresultSelector: Selector<TAccumulate, TResult>

        Optional projection applied to the final accumulator before it is resolved.

      Returns Promise<TAccumulate | TResult>

      A promise that resolves to the final accumulator (or its projection).

      Thrown when the sequence is empty and no seed is provided.

      The source sequence is enumerated asynchronously exactly once. Supply a seed to avoid exceptions on empty sequences and to control the accumulator type.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const sum = await numbers.aggregate((acc, x) => acc + x);
      console.log(sum); // 15

      const product = await numbers.aggregate((acc, x) => acc * x, 1);
      console.log(product); // 120
    • Determines whether every element in the sequence satisfies the supplied predicate.

      Parameters

      • predicate: Predicate<TElement>

        Function that evaluates each element and returns true when it satisfies the condition.

      Returns Promise<boolean>

      true when all elements satisfy the predicate; otherwise, false.

      Enumeration stops as soon as the predicate returns false.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const allPositive = await numbers.all(x => x > 0);
      console.log(allPositive); // true

      const mixedNumbers = fromAsync([-1, 2, 3, -4, 5]);
      const allPositive2 = await mixedNumbers.all(x => x > 0);
      console.log(allPositive2); // false
    • Determines whether the sequence contains at least one element that matches the optional predicate.

      Parameters

      • Optionalpredicate: Predicate<TElement>

        Optional function used to test elements. When omitted, the method resolves to true if the sequence contains any element.

      Returns Promise<boolean>

      true when a matching element is found; otherwise, false.

      When the predicate is omitted, only the first element is inspected, making this more efficient than awaiting count() > 0.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const hasEvenNumber = await numbers.any(x => x % 2 === 0);
      console.log(hasEvenNumber); // true

      const oddNumbers = fromAsync([1, 3, 5]);
      const hasEvenNumber2 = await oddNumbers.any(x => x % 2 === 0);
      console.log(hasEvenNumber2); // false
    • Creates an async sequence that yields the current elements followed by the supplied element.

      Parameters

      • element: TElement

        Element appended to the end of the sequence.

      Returns IAsyncEnumerable<TElement>

      A new async enumerable whose final item is the provided element.

      The source sequence is not modified; enumeration is deferred until the returned sequence is iterated.

      const numbers = fromAsync([1, 2, 3]);
      const appended = await numbers.append(4).toArray();
      console.log(appended); // [1, 2, 3, 4]
    • Determines whether the async sequence contains at least count elements that satisfy the optional predicate.

      Parameters

      • count: number

        Minimum number of matching elements required. Must be greater than or equal to 0.

      • Optionalpredicate: Predicate<TElement>

        Optional predicate that determines which elements are counted. When omitted, every element is considered a match.

      Returns Promise<boolean>

      true when at least count matching elements are present; otherwise, false.

      Thrown when count is negative.

      Re-throws any error encountered while asynchronously iterating the sequence or executing the predicate.

      Enumeration stops as soon as the required number of matches is found, avoiding unnecessary work on long sequences.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const hasAtLeastTwoEvens = await numbers.atLeast(2, n => n % 2 === 0);
      console.log(hasAtLeastTwoEvens); // true
    • Determines whether the async sequence contains no more than count elements that satisfy the optional predicate.

      Parameters

      • count: number

        Maximum number of matching elements allowed. Must be greater than or equal to 0.

      • Optionalpredicate: Predicate<TElement>

        Optional predicate that determines which elements are counted. When omitted, every element is considered a match.

      Returns Promise<boolean>

      true when the number of matching elements does not exceed count; otherwise, false.

      Thrown when count is negative.

      Re-throws any error encountered while asynchronously iterating the sequence or executing the predicate.

      Enumeration stops as soon as the count is exceeded, making it efficient for large or infinite sequences.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const hasAtMostOneEven = await numbers.atMost(1, n => n % 2 === 0);
      console.log(hasAtMostOneEven); // false
    • Computes the arithmetic mean of the numeric values produced for each element in the sequence.

      Parameters

      • Optionalselector: Selector<TElement, number>

        Optional projection that extracts the numeric value for each element. Defaults to the element itself.

      Returns Promise<number>

      A promise that resolves to the arithmetic mean of the selected values.

      Thrown when the sequence is empty.

      Provide a selector when the elements are not already numeric. All values are enumerated exactly once.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const avg = await numbers.average();
      console.log(avg); // 3

      const people = fromAsync([
      { name: 'Alice', age: 25 },
      { name: 'Bob', age: 30 },
      { name: 'Charlie', age: 35 },
      ]);
      const avgAge = await people.average(p => p.age);
      console.log(avgAge); // 30
    • Produces the cartesian product between this async sequence and iterable.

      Type Parameters

      • TSecond

        Type of elements emitted by iterable.

      Parameters

      • iterable: AsyncIterable<TSecond>

        The secondary async sequence paired with every element from the source.

      Returns IAsyncEnumerable<[TElement, TSecond]>

      A deferred async sequence that yields each ordered pair [source, other].

      Re-throws any error raised while asynchronously iterating the source or iterable.

      The secondary sequence is fully buffered before iteration starts so that it can be replayed for every source element. The resulting sequence stops when the source sequence completes.

      const pairs = await fromAsync([1, 2]).cartesian(fromAsync(['A', 'B'])).toArray();
      console.log(pairs); // [[1, 'A'], [1, 'B'], [2, 'A'], [2, 'B']]
    • Reinterprets each element in the async sequence as the specified result type.

      Type Parameters

      • TResult

        Target type exposed by the returned sequence.

      Returns IAsyncEnumerable<TResult>

      An async sequence that yields the same elements typed as TResult.

      No runtime conversion occurs; ensure the underlying elements are compatible with TResult to avoid downstream failures.

      const mixed = fromAsync([1, 'two', 3, 'four']);
      const numbers = mixed.cast<number>().where(x => typeof x === 'number');
      console.log(await numbers.toArray()); // [1, 3]
    • Splits the sequence into contiguous subsequences containing at most the specified number of elements.

      Parameters

      • size: number

        Maximum number of elements to include in each chunk. Must be greater than 0.

      Returns IAsyncEnumerable<IEnumerable<TElement>>

      An async sequence whose elements are chunks of the original sequence.

      Thrown when size is less than 1.

      Each chunk is yielded as an IEnumerable<TElement>. The final chunk may contain fewer elements than size.

      const numbers = fromAsync([1, 2, 3, 4, 5, 6, 7, 8]);
      const chunks = numbers.chunk(3);
      const result = await chunks.select(c => c.toArray()).toArray();
      console.log(result); // [[1, 2, 3], [4, 5, 6], [7, 8]]
    • Generates the unique combinations that can be built from the elements in the async sequence.

      Parameters

      • Optionalsize: number

        Optional number of elements that each combination must contain. When omitted, combinations of every possible length are produced.

      Returns IAsyncEnumerable<IEnumerable<TElement>>

      An async sequence of combinations built from the source elements.

      Thrown when size is negative.

      The source sequence is materialised before combinations are produced, so very large inputs can be expensive. Duplicate combinations produced by repeated elements are emitted only once.

      const numbers = fromAsync([1, 2, 3]);
      const combs = numbers.combinations(2);
      const result = await combs.select(c => c.toArray()).toArray();
      console.log(result); // [[1, 2], [1, 3], [2, 3]]
    • Filters out null and undefined values from the async sequence.

      Returns IAsyncEnumerable<NonNullable<TElement>>

      An async sequence containing only elements that are neither null nor undefined.

      The method preserves other falsy values (such as 0 or an empty string) and defers execution until the result is iterated.

      const values = await fromAsync([1, null, 0, undefined]).compact().toArray();
      console.log(values); // [1, 0]
    • Appends the specified async iterable to the end of the sequence.

      Parameters

      • other: AsyncIterable<TElement>

        Additional elements that are yielded after the current sequence.

      Returns IAsyncEnumerable<TElement>

      An async sequence containing the elements of the current sequence followed by those from other.

      Enumeration of both sequences is deferred until the result is iterated.

      const numbers1 = fromAsync([1, 2, 3]);
      const numbers2 = [4, 5, 6];
      const concatenated = await numbers1.concat(numbers2).toArray();
      console.log(concatenated); // [1, 2, 3, 4, 5, 6]
    • Determines whether the async sequence contains a specific element using an optional comparator.

      Parameters

      • element: TElement

        Element to locate in the sequence.

      • Optionalcomparator: EqualityComparator<TElement, TElement>

        Optional equality comparator used to match elements. Defaults to the library's standard equality comparison.

      Returns Promise<boolean>

      true when the element is found; otherwise, false.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const hasThree = await numbers.contains(3);
      console.log(hasThree); // true

      const hasTen = await numbers.contains(10);
      console.log(hasTen); // false
    • Computes the Pearson correlation coefficient between this async sequence and iterable.

      Type Parameters

      • TSecond

        Type of elements produced by iterable.

      Parameters

      • iterable: AsyncIterable<TSecond>

        Async sequence whose elements align by index with the source sequence.

      • Optionalselector: Selector<TElement, number>

        Optional projection that extracts the numeric value for each element of the source sequence. Defaults to treating the element itself as numeric.

      • OptionalotherSelector: Selector<TSecond, number>

        Optional projection that extracts the numeric value for each element of iterable. Defaults to treating the element itself as numeric.

      Returns Promise<number>

      A promise that resolves to the correlation coefficient in the interval [-1, 1].

      Thrown when the sequences do not contain the same number of elements.

      Thrown when fewer than two aligned pairs are available.

      Thrown when the standard deviation of either numeric projection is zero.

      Re-throws any error encountered while asynchronously iterating the source, iterable, or executing the selector projections.

      Both sequences are consumed simultaneously via an online algorithm that avoids buffering the full dataset. Ensure the async iterables are aligned because mismatch detection occurs only after iteration begins.

      const temperatures = fromAsync([15, 18, 21, 24]);
      const sales = fromAsync([30, 36, 42, 48]);
      const correlation = await temperatures.correlation(sales);
      console.log(correlation); // 1
    • Computes the Pearson correlation coefficient between two numeric projections of the async sequence.

      Parameters

      • leftSelector: Selector<TElement, number>

        Projection that produces the first numeric series for each element.

      • rightSelector: Selector<TElement, number>

        Projection that produces the second numeric series for each element.

      Returns Promise<number>

      A promise that resolves to the correlation coefficient in the interval [-1, 1].

      Thrown when fewer than two elements are available.

      Thrown when the standard deviation of either numeric projection is zero.

      Re-throws any error encountered while iterating the sequence or executing the selector projections.

      The sequence is consumed exactly once using an online algorithm, which keeps memory usage constant even for large inputs.

      const metrics = fromAsync([
      { impressions: 1_000, clicks: 50 },
      { impressions: 1_500, clicks: 75 },
      { impressions: 2_000, clicks: 100 }
      ]);
      const correlation = await metrics.correlationBy(m => m.impressions, m => m.clicks);
      console.log(correlation); // 1
    • Counts the number of elements in the async sequence, optionally restricted by a predicate.

      Parameters

      • Optionalpredicate: Predicate<TElement>

        Optional predicate that determines which elements are counted. When omitted, all elements are counted.

      Returns Promise<number>

      A promise that resolves to the number of elements that satisfy the predicate.

      Prefer calling any() to test for existence instead of comparing this result with zero.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const totalCount = await numbers.count();
      console.log(totalCount); // 5

      const evenCount = await numbers.count(x => x % 2 === 0);
      console.log(evenCount); // 2
    • Counts the occurrences of elements grouped by a derived key.

      Type Parameters

      • TKey

        Type produced by keySelector.

      Parameters

      • keySelector: Selector<TElement, TKey>

        Selector used to derive the grouping key for each element.

      • Optionalcomparator: EqualityComparator<TKey, TKey>

        Optional equality comparator used to match keys. Defaults to the library's standard equality comparison.

      Returns IAsyncEnumerable<KeyValuePair<TKey, number>>

      An async sequence of key/count pairs describing how many elements share each key.

      Each key appears exactly once in the result with its associated occurrence count.

      const products = fromAsync([
      { name: 'Apple', category: 'Fruit' },
      { name: 'Banana', category: 'Fruit' },
      { name: 'Carrot', category: 'Vegetable' },
      ]);

      const countByCategory = await products.countBy(p => p.category).toArray();
      console.log(countByCategory);
      // [
      // { key: 'Fruit', value: 2 },
      // { key: 'Vegetable', value: 1 }
      // ]
    • Calculates the covariance between this async sequence and iterable.

      Type Parameters

      • TSecond

        Type of elements produced by iterable.

      Parameters

      • iterable: AsyncIterable<TSecond>

        Async sequence whose elements align by index with the source sequence.

      • Optionalselector: Selector<TElement, number>

        Optional projection that extracts the numeric value for each element in the source sequence. Defaults to treating the element itself as numeric.

      • OptionalotherSelector: Selector<TSecond, number>

        Optional projection that extracts the numeric value for each element in iterable. Defaults to treating the element itself as numeric.

      • Optionalsample: boolean

        When true, computes the sample covariance dividing by n - 1; when false, computes the population covariance dividing by n. Defaults to true.

      Returns Promise<number>

      A promise that resolves to the calculated covariance.

      Thrown when the sequences do not contain the same number of elements.

      Thrown when fewer than two aligned pairs are available.

      Re-throws any error thrown while iterating either sequence or executing the selector projections.

      Both sequences are consumed simultaneously so that streaming statistics can be computed without materialising all elements. Align the sequences carefully, as mismatch detection occurs only after enumeration begins.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const doubles = fromAsync([2, 4, 6, 8, 10]);
      const covariance = await numbers.covariance(doubles);
      console.log(covariance); // 5
    • Calculates the covariance between two numeric projections of the async sequence.

      Parameters

      • leftSelector: Selector<TElement, number>

        Projection that produces the first numeric series for each element.

      • rightSelector: Selector<TElement, number>

        Projection that produces the second numeric series for each element.

      • Optionalsample: boolean

        When true, computes the sample covariance dividing by n - 1; when false, computes the population covariance dividing by n. Defaults to true.

      Returns Promise<number>

      A promise that resolves to the calculated covariance.

      Thrown when fewer than two elements are available.

      Re-throws any error thrown while iterating the sequence or executing the selector projections.

      The sequence is consumed exactly once using an online algorithm that avoids buffering, making it suitable for large datasets.

      const pairs = fromAsync([
      { x: 1, y: 2 },
      { x: 2, y: 4 },
      { x: 3, y: 6 }
      ]);
      const covariance = await pairs.covarianceBy(p => p.x, p => p.y);
      console.log(covariance); // 2
    • Repeats the async sequence the specified number of times, or indefinitely when no count is provided.

      Parameters

      • Optionalcount: number

        Optional number of times to repeat the sequence. When omitted, the sequence repeats without end.

      Returns IAsyncEnumerable<TElement>

      An async sequence that yields the original elements cyclically.

      Thrown when the sequence is empty.

      When count is undefined, consume the result with care because it represents an infinite sequence.

      const numbers = fromAsync([1, 2, 3]);
      const cycled = await numbers.cycle(2).toArray();
      console.log(cycled); // [1, 2, 3, 1, 2, 3]
    • Supplies fallback content when the async sequence contains no elements.

      Parameters

      • OptionaldefaultValue: TElement | null

        Optional value returned in a singleton sequence when the source is empty. Defaults to null.

      Returns IAsyncEnumerable<TElement | null>

      The original sequence when it has elements; otherwise, a singleton sequence containing the provided value.

      Use this to guarantee that downstream async operators receive at least one element.

      const empty = fromAsync([]);
      const withDefault = await empty.defaultIfEmpty(0).toArray();
      console.log(withDefault); // [0]

      const numbers = fromAsync([1, 2, 3]);
      const withDefault2 = await numbers.defaultIfEmpty(0).toArray();
      console.log(withDefault2); // [1, 2, 3]
    • Determines whether the async sequence and iterable share no equivalent elements.

      Type Parameters

      • TSecond

        Type of elements yielded by iterable.

      Parameters

      • iterable: AsyncIterable<TSecond>

        Async sequence compared against the source.

      • Optionalcomparator: EqualityComparator<TElement | TSecond, TElement | TSecond>

        Optional equality comparator used to match elements across both sequences. Defaults to the library's standard equality comparison.

      Returns Promise<boolean>

      A promise that resolves to true when the sequences are disjoint; otherwise, false.

      Re-throws any error encountered while asynchronously iterating the source, iterable, or executing the comparator.

      When the default comparator is used, the method buffers the source elements in a Set so it can short-circuit as soon as a shared element is detected. When a custom comparator is supplied, both sequences are materialised to avoid repeated enumeration.

      const first = fromAsync([1, 2, 3]);
      const second = fromAsync([4, 5, 6]);
      const areDisjoint = await first.disjoint(second);
      console.log(areDisjoint); // true
    • Determines whether the key projections of the async sequence and iterable are mutually exclusive.

      Type Parameters

      Parameters

      Returns Promise<boolean>

      A promise that resolves to true when no projected keys intersect; otherwise, false.

      Re-throws any error encountered while iterating either sequence or executing the selector projections/comparator.

      When the default comparator is used, the method buffers the larger key collection in a Set and short-circuits as soon as an intersecting key is found. Supplying a custom comparator materialises both key collections and compares each pair, so prefer the default when suitable.

      const left = fromAsync([{ name: 'Alice' }, { name: 'Bella' }]);
      const right = fromAsync([{ name: 'Mel' }]);
      const areDisjoint = await left.disjointBy(right, p => p.name, p => p.name);
      console.log(areDisjoint); // true
    • Eliminates duplicate elements by comparing keys computed for each async element.

      Type Parameters

      • TKey

        Key type returned by keySelector.

      Parameters

      • keySelector: Selector<TElement, TKey>

        Selector used to project each element to the key used for distinctness.

      • OptionalkeyComparator: EqualityComparator<TKey, TKey>

        Optional equality comparator used to compare keys. Defaults to the library's standard equality comparison.

      Returns IAsyncEnumerable<TElement>

      An async sequence that contains the first occurrence of each unique key.

      Each element's key is evaluated exactly once; cache expensive key computations when possible.

      const products = fromAsync([
      { name: 'Apple', category: 'Fruit' },
      { name: 'Banana', category: 'Fruit' },
      { name: 'Carrot', category: 'Vegetable' },
      ]);

      const distinctByCategory = await products.distinctBy(p => p.category).toArray();
      console.log(distinctByCategory);
      // [
      // { name: 'Apple', category: 'Fruit' },
      // { name: 'Carrot', category: 'Vegetable' }
      // ]
    • Removes consecutive duplicate elements by comparing keys projected from each element.

      Type Parameters

      • TKey

        Key type returned by keySelector.

      Parameters

      • keySelector: Selector<TElement, TKey>

        Selector used to project each element to the key used for comparison.

      • OptionalkeyComparator: EqualityComparator<TKey, TKey>

        Optional equality comparator used to compare keys. Defaults to the library's standard equality comparison.

      Returns IAsyncEnumerable<TElement>

      An async sequence that yields the first element in each run of elements whose keys change.

      Enumeration stops comparing elements once a different key is encountered, making this useful for collapsing grouped async data.

      const products = fromAsync([
      { name: 'Apple', category: 'Fruit' },
      { name: 'Banana', category: 'Fruit' },
      { name: 'Carrot', category: 'Vegetable' },
      { name: 'Broccoli', category: 'Vegetable' },
      { name: 'Orange', category: 'Fruit' },
      ]);

      const distinctByCategory = await products.distinctUntilChangedBy(p => p.category).toArray();
      console.log(distinctByCategory);
      // [
      // { name: 'Apple', category: 'Fruit' },
      // { name: 'Carrot', category: 'Vegetable' },
      // { name: 'Orange', category: 'Fruit' }
      // ]
    • Asynchronously retrieves the element at the specified zero-based index.

      Parameters

      • index: number

        Zero-based position of the element to retrieve.

      Returns Promise<TElement>

      A promise that resolves to the element located at the requested index.

      Thrown when index is negative or greater than or equal to the number of elements in the sequence.

      Thrown when the sequence terminates unexpectedly before yielding the requested element.

      Enumeration stops once the requested element is found; remaining elements are not evaluated.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const element = await numbers.elementAt(2);
      console.log(element); // 3
    • Asynchronously retrieves the element at the specified zero-based index or resolves to null when the index is out of range.

      Parameters

      • index: number

        Zero-based position of the element to retrieve.

      Returns Promise<TElement | null>

      A promise that resolves to the element at index, or null when the sequence is shorter than index + 1 or when index is negative.

      Use this overload when out-of-range access should produce a sentinel value instead of throwing an exception.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const element = await numbers.elementAtOrDefault(2);
      console.log(element); // 3

      const element2 = await numbers.elementAtOrDefault(10);
      console.log(element2); // null
    • Determines whether the async sequence contains exactly count elements that satisfy the optional predicate.

      Parameters

      • count: number

        Exact number of matching elements required. Must be greater than or equal to 0.

      • Optionalpredicate: Predicate<TElement>

        Optional predicate that determines which elements are counted. When omitted, every element is considered a match.

      Returns Promise<boolean>

      true when exactly count matching elements are present; otherwise, false.

      Thrown when count is negative.

      Re-throws any error encountered while asynchronously iterating the sequence or executing the predicate.

      Enumeration stops once the running total exceeds count, preventing unnecessary work.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const hasExactlyThreeOdds = await numbers.exactly(3, n => n % 2 !== 0);
      console.log(hasExactlyThreeOdds); // true
    • Returns the elements of this async sequence whose projected keys are not present in the specified async iterable.

      Type Parameters

      • TKey

        Type produced by keySelector.

      Parameters

      • enumerable: AsyncIterable<TElement>

        Async sequence whose elements define the keys that should be excluded.

      • keySelector: Selector<TElement, TKey>

        Selector used to project each element to the key used for comparison.

      • Optionalcomparator: EqualityComparator<TKey, TKey> | OrderComparator<TKey, TKey>

        Optional comparator used to compare keys. Both equality and order comparators are supported; defaults to the library's standard equality comparison when omitted.

      Returns IAsyncEnumerable<TElement>

      An async sequence that contains the elements from this sequence whose keys are absent from enumerable.

      Source ordering is preserved and duplicate elements with distinct keys remain. The exclusion keys are materialised by fully enumerating enumerable.

      const products1 = fromAsync([
      { name: 'Apple', category: 'Fruit' },
      { name: 'Banana', category: 'Fruit' },
      { name: 'Carrot', category: 'Vegetable' },
      ]);
      const products2 = [
      { name: 'Broccoli', category: 'Vegetable' },
      ];

      const result = await products1.exceptBy(products2, p => p.category).toArray();
      console.log(result);
      // [
      // { name: 'Apple', category: 'Fruit' },
      // { name: 'Banana', category: 'Fruit' }
      // ]
    • Asynchronously returns the first element that satisfies the provided type guard.

      Type Parameters

      • TFiltered

        Subtype confirmed by the type guard.

      Parameters

      Returns Promise<TFiltered>

      A promise that resolves to the first element satisfying the type guard.

      Thrown when the sequence is empty.

      Thrown when no element satisfies the type guard.

      Enumeration stops immediately once a matching element is found.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const firstElement = await numbers.first();
      console.log(firstElement); // 1

      const firstEven = await numbers.first(x => x % 2 === 0);
      console.log(firstEven); // 2
    • Asynchronously returns the first element in the sequence, optionally filtered by a predicate.

      Parameters

      • Optionalpredicate: Predicate<TElement>

        Predicate evaluated against each element; when omitted, the first element is returned.

      Returns Promise<TElement>

      A promise that resolves to the first element satisfying the predicate (or the very first element when none is provided).

      Thrown when the sequence is empty.

      Thrown when a predicate is supplied and no element satisfies it.

      Enumeration stops immediately once a matching element is found.

    • Asynchronously returns the first element that satisfies the provided type guard, or null when no such element exists.

      Type Parameters

      • TFiltered

        Subtype confirmed by the type guard.

      Parameters

      Returns Promise<TFiltered | null>

      A promise that resolves to the first element satisfying the type guard, or null when none match.

      Enumeration stops immediately once a matching element is found.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const firstElement = await numbers.firstOrDefault();
      console.log(firstElement); // 1

      const firstEven = await numbers.firstOrDefault(x => x % 2 === 0);
      console.log(firstEven); // 2

      const empty = fromAsync<number>([]);
      const firstOfEmpty = await empty.firstOrDefault();
      console.log(firstOfEmpty); // null

      const noEvens = fromAsync([1, 3, 5]);
      const firstEven2 = await noEvens.firstOrDefault(x => x % 2 === 0);
      console.log(firstEven2); // null
    • Asynchronously returns the first element in the sequence or null when the sequence is empty or no element satisfies the predicate.

      Parameters

      • Optionalpredicate: Predicate<TElement>

        Predicate evaluated against each element; when omitted, the first element is returned.

      Returns Promise<TElement | null>

      A promise that resolves to the first matching element, or null when no match is found.

      This method never rejects for missing elements; it communicates absence through the null result.

    • Executes the provided callback for every element in the async sequence.

      Parameters

      • action: IndexedAction<TElement>

        Callback invoked for each element; receives the element and its zero-based index.

      Returns Promise<void>

      A promise that resolves when iteration completes.

      Enumeration starts immediately. Avoid mutating the underlying collection while iterating.

      const numbers = fromAsync([1, 2, 3]);
      await numbers.forEach((x, i) => console.log(`Index ${i}: ${x}`));
      // Index 0: 1
      // Index 1: 2
      // Index 2: 3
    • Partitions the async sequence into groups based on keys projected from each element.

      Type Parameters

      Parameters

      • keySelector: Selector<TElement, TKey>

        Selector used to derive the grouping key for each element.

      • OptionalkeyComparator: EqualityComparator<TKey, TKey>

        Optional equality comparator used to match keys. Defaults to the library's standard equality comparison.

      Returns IAsyncEnumerable<IGroup<TKey, TElement>>

      An async sequence of groups, each exposing the key and the elements that share it.

      The source sequence is enumerated once when the result is iterated. Elements within each group preserve their original order, and group contents are cached for repeated enumeration.

      const products = fromAsync([
      { name: 'Apple', category: 'Fruit' },
      { name: 'Banana', category: 'Fruit' },
      { name: 'Carrot', category: 'Vegetable' },
      ]);

      const grouped = products.groupBy(p => p.category);
      for await (const group of grouped) {
      console.log(group.key, group.toArray());
      }
      // Fruit [ { name: 'Apple', category: 'Fruit' }, { name: 'Banana', category: 'Fruit' } ]
      // Vegetable [ { name: 'Carrot', category: 'Vegetable' } ]
    • Correlates each element of the async sequence with a collection of matching elements from another async sequence.

      Type Parameters

      • TInner

        Type of elements in the inner sequence.

      • TKey

        Type of key produced by the key selectors.

      • TResult

        Type of element returned by resultSelector.

      Parameters

      Returns IAsyncEnumerable<TResult>

      An async sequence produced by applying resultSelector to each outer element and its matching inner elements.

      The inner sequence is enumerated once to build an in-memory lookup before outer elements are processed. Each outer element is then evaluated lazily and preserves the original outer ordering.

      const categories = fromAsync([
      { id: 1, name: 'Fruit' },
      { id: 2, name: 'Vegetable' },
      ]);
      const products = fromAsync([
      { name: 'Apple', categoryId: 1 },
      { name: 'Banana', categoryId: 1 },
      { name: 'Carrot', categoryId: 2 },
      ]);

      const joined = await categories.groupJoin(
      products,
      c => c.id,
      p => p.categoryId,
      (c, ps) => ({ ...c, products: ps.toArray() })
      ).toArray();

      console.log(joined);
      // [
      // { id: 1, name: 'Fruit', products: [ { name: 'Apple', categoryId: 1 }, { name: 'Banana', categoryId: 1 } ] },
      // { id: 2, name: 'Vegetable', products: [ { name: 'Carrot', categoryId: 2 } ] }
      // ]
    • Enumerates the async sequence while exposing the zero-based index alongside each element.

      Returns IAsyncEnumerable<[number, TElement]>

      An async sequence of [index, element] tuples.

      The index is assigned in the order elements are produced. Enumeration is deferred until the result is iterated.

      const letters = fromAsync(['a', 'b', 'c']);
      const indexed = await letters.index().toArray();
      console.log(indexed); // [[0, 'a'], [1, 'b'], [2, 'c']]
    • Interleaves the async sequence with another iterable, yielding elements in alternating order.

      Type Parameters

      • TSecond

        Type of elements in the second iterable.

      Parameters

      • iterable: AsyncIterable<TSecond>

        Async iterable whose elements are alternated with the current sequence.

      Returns IAsyncEnumerable<TElement | TSecond>

      An async sequence that alternates between elements from this sequence and iterable.

      If one sequence is longer, the remaining elements are appended after the shorter sequence is exhausted. Enumeration is deferred.

      const numbers1 = fromAsync([1, 3, 5]);
      const numbers2 = [2, 4, 6];
      const interleaved = await numbers1.interleave(numbers2).toArray();
      console.log(interleaved); // [1, 2, 3, 4, 5, 6]
    • Returns the elements whose keys are common to this async sequence and the specified iterable.

      Type Parameters

      Parameters

      • enumerable: AsyncIterable<TElement>

        Async sequence whose elements define the keys considered part of the intersection.

      • keySelector: Selector<TElement, TKey>

        Selector used to project each element to the key used for comparison.

      • Optionalcomparator: EqualityComparator<TKey, TKey> | OrderComparator<TKey, TKey>

        Optional comparator used to compare keys. Both equality and order comparators are supported; defaults to the library's standard equality comparison when omitted.

      Returns IAsyncEnumerable<TElement>

      An async sequence containing the intersection of the two sequences based on matching keys.

      The enumerable is fully enumerated to materialise the inclusion keys before yielding results. Source ordering is preserved.

      const products1 = fromAsync([
      { name: 'Apple', category: 'Fruit' },
      { name: 'Carrot', category: 'Vegetable' },
      ]);
      const products2 = [
      { name: 'Banana', category: 'Fruit' },
      { name: 'Broccoli', category: 'Vegetable' },
      ];

      const result = await products1.intersectBy(products2, p => p.category).toArray();
      console.log(result);
      // [
      // { name: 'Apple', category: 'Fruit' },
      // { name: 'Carrot', category: 'Vegetable' }
      // ]
    • Produces a projection from the async sequence and a second async sequence by matching elements that share an identical join key.

      Type Parameters

      • TInner

        Type of elements in the inner sequence.

      • TKey

        Type of key produced by the key selectors.

      • TResult

        Type of element returned by resultSelector.

      Parameters

      • inner: IAsyncEnumerable<TInner>

        Async sequence whose elements are joined with the outer sequence.

      • outerKeySelector: Selector<TElement, TKey>

        Selector that extracts the join key from each outer element.

      • innerKeySelector: Selector<TInner, TKey>

        Selector that extracts the join key from each inner element.

      • resultSelector: JoinSelector<TElement, TInner, TResult>

        Projection that combines an outer element with a matching inner element.

      • OptionalkeyComparator: EqualityComparator<TKey, TKey>

        Optional equality comparator used to match keys. Defaults to the library's standard equality comparison when omitted.

      Returns IAsyncEnumerable<TResult>

      An async sequence generated by applying resultSelector to each matching pair.

      The inner sequence is fully enumerated to build an in-memory lookup before outer elements are processed. The outer sequence is then enumerated lazily and its original ordering is preserved. This is an inner join; unmatched outer or inner elements are not emitted.

      const categories = fromAsync([
      { id: 1, name: 'Fruit' },
      { id: 2, name: 'Vegetable' },
      ]);
      const products = fromAsync([
      { name: 'Apple', categoryId: 1 },
      { name: 'Banana', categoryId: 1 },
      { name: 'Carrot', categoryId: 2 },
      ]);

      const joined = await categories.join(
      products,
      c => c.id,
      p => p.categoryId,
      (c, p) => ({ category: c.name, product: p.name })
      ).toArray();

      console.log(joined);
      // [
      // { category: 'Fruit', product: 'Apple' },
      // { category: 'Fruit', product: 'Banana' },
      // { category: 'Vegetable', product: 'Carrot' }
      // ]
    • Asynchronously returns the last element that satisfies the provided type guard.

      Type Parameters

      • TFiltered

        Subtype confirmed by the type guard.

      Parameters

      • predicate: TypePredicate<TElement, TFiltered>

        Type guard evaluated against each element. Every matching element becomes a candidate, and the final match is returned.

      Returns Promise<TFiltered>

      A promise that resolves to the last element that satisfies the type guard.

      Thrown when the sequence is empty.

      Thrown when no element satisfies the type guard.

      The entire sequence is enumerated to locate the final match.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const lastElement = await numbers.last();
      console.log(lastElement); // 5

      const lastEven = await numbers.last(x => x % 2 === 0);
      console.log(lastEven); // 4
    • Asynchronously returns the last element in the sequence, optionally filtered by a predicate.

      Parameters

      • Optionalpredicate: Predicate<TElement>

        Predicate evaluated against each element. When omitted, the last element of the sequence is returned.

      Returns Promise<TElement>

      A promise that resolves to the last element that satisfies the predicate (or the final element when no predicate is supplied).

      Thrown when the sequence is empty.

      Thrown when a predicate is supplied and no element satisfies it.

      The entire sequence is enumerated to locate the final match.

    • Asynchronously returns the last element that satisfies the provided type guard, or null when no such element exists.

      Type Parameters

      • TFiltered

        Subtype confirmed by the type guard.

      Parameters

      • predicate: TypePredicate<TElement, TFiltered>

        Type guard evaluated against each element. Every matching element becomes a candidate, and the final match is returned.

      Returns Promise<TFiltered | null>

      A promise that resolves to the last element that satisfies the type guard, or null when none match.

      The entire sequence is enumerated to locate the final match. This overload never rejects for missing elements; it communicates absence through the null result.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const lastElement = await numbers.lastOrDefault();
      console.log(lastElement); // 5

      const lastEven = await numbers.lastOrDefault(x => x % 2 === 0);
      console.log(lastEven); // 4

      const empty = fromAsync<number>([]);
      const lastOfEmpty = await empty.lastOrDefault();
      console.log(lastOfEmpty); // null

      const noEvens = fromAsync([1, 3, 5]);
      const lastEven2 = await noEvens.lastOrDefault(x => x % 2 === 0);
      console.log(lastEven2); // null
    • Asynchronously returns the last element in the sequence or null when the sequence is empty or no element satisfies the predicate.

      Parameters

      • Optionalpredicate: Predicate<TElement>

        Predicate evaluated against each element. When omitted, the last element of the sequence is returned.

      Returns Promise<TElement | null>

      A promise that resolves to the last element that satisfies the predicate, or null when no match is found.

      The entire sequence is enumerated to locate the final match. This overload never rejects for missing elements; it communicates absence through the null result.

    • Asynchronously returns the largest numeric value produced for the elements in the sequence.

      Parameters

      • Optionalselector: Selector<TElement, number>

        Optional projection that extracts the numeric value for each element. Defaults to the element itself.

      Returns Promise<number>

      A promise that resolves to the maximum of the projected values.

      Thrown when the sequence is empty.

      The entire sequence is enumerated exactly once. Provide a selector when the elements are not already numeric.

      const numbers = fromAsync([1, 5, 2, 4, 3]);
      const maxNumber = await numbers.max();
      console.log(maxNumber); // 5

      const people = fromAsync([
      { name: 'Alice', age: 25 },
      { name: 'Bob', age: 30 },
      { name: 'Charlie', age: 28 },
      ]);
      const maxAge = await people.max(p => p.age);
      console.log(maxAge); // 30
    • Asynchronously returns the element whose projected key is greatest according to the provided comparator.

      Type Parameters

      Parameters

      • keySelector: Selector<TElement, TKey>

        Selector used to project each element to the key used for comparison.

      • Optionalcomparator: OrderComparator<TKey, TKey>

        Optional order comparator used to compare keys. Defaults to the library's standard order comparison when omitted.

      Returns Promise<TElement>

      A promise that resolves to the element whose key is maximal.

      Thrown when the sequence is empty.

      When multiple elements share the maximal key, the first such element in the sequence is returned.

      const people = fromAsync([
      { name: 'Alice', age: 25 },
      { name: 'Bob', age: 30 },
      { name: 'Charlie', age: 28 },
      ]);
      const oldestPerson = await people.maxBy(p => p.age);
      console.log(oldestPerson); // { name: 'Bob', age: 30 }
    • Calculates the median of the numeric values produced by the async sequence.

      Parameters

      • Optionalselector: Selector<TElement, number>

        Optional projection that extracts the numeric value for each element. Defaults to treating the element itself as numeric.

      • Optionaltie: MedianTieStrategy

        Determines how the median is resolved when the sequence contains an even number of elements. Defaults to "interpolate", which averages the two central values. Specify "low" or "high" to select the lower or higher neighbour respectively.

      Returns Promise<number>

      A promise that resolves to the calculated median, or NaN when the sequence contains no elements.

      Re-throws any error thrown while iterating the sequence or executing selector.

      The sequence is fully consumed and buffered so a selection algorithm can locate the middle element(s) without fully sorting. Supply selector when the elements are not already numeric.

      const medianValue = await fromAsync([1, 5, 2, 4, 3]).median();
      console.log(medianValue); // 3

      const people = fromAsync([
      { name: 'Alice', age: 23 },
      { name: 'Bella', age: 21 },
      { name: 'Mirei', age: 22 },
      { name: 'Hanna', age: 20 },
      { name: 'Noemi', age: 29 }
      ]);
      const medianAge = await people.median(p => p.age);
      console.log(medianAge); // 22
    • Asynchronously returns the smallest numeric value produced for the elements in the sequence.

      Parameters

      • Optionalselector: Selector<TElement, number>

        Optional projection that extracts the numeric value for each element. Defaults to the element itself.

      Returns Promise<number>

      A promise that resolves to the minimum of the projected values.

      Thrown when the sequence is empty.

      The entire sequence is enumerated exactly once. Provide a selector when the elements are not already numeric.

      const numbers = fromAsync([3, 1, 5, 2, 4]);
      const minNumber = await numbers.min();
      console.log(minNumber); // 1

      const people = fromAsync([
      { name: 'Alice', age: 25 },
      { name: 'Bob', age: 30 },
      { name: 'Charlie', age: 22 },
      ]);
      const minAge = await people.min(p => p.age);
      console.log(minAge); // 22
    • Asynchronously returns the element whose projected key is smallest according to the provided comparator.

      Type Parameters

      Parameters

      • keySelector: Selector<TElement, TKey>

        Selector used to project each element to the key used for comparison.

      • Optionalcomparator: OrderComparator<TKey, TKey>

        Optional order comparator used to compare keys. Defaults to the library's standard order comparison when omitted.

      Returns Promise<TElement>

      A promise that resolves to the element whose key is minimal.

      Thrown when the sequence is empty.

      When multiple elements share the minimal key, the first such element in the sequence is returned.

      const people = fromAsync([
      { name: 'Alice', age: 25 },
      { name: 'Bob', age: 30 },
      { name: 'Charlie', age: 22 },
      ]);
      const youngestPerson = await people.minBy(p => p.age);
      console.log(youngestPerson); // { name: 'Charlie', age: 22 }
    • Asynchronously returns the element that appears most frequently in the sequence.

      Type Parameters

      Parameters

      • OptionalkeySelector: Selector<TElement, TKey>

        Optional selector that projects each element to the key used for frequency counting. Defaults to the element itself.

      Returns Promise<TElement>

      A promise that resolves to the first element whose occurrence count matches the maximum frequency.

      Thrown when the sequence is empty.

      Re-throws any error thrown while iterating the sequence or executing keySelector.

      The entire sequence is consumed to build frequency counts before the mode is resolved. When multiple keys share the same frequency, the earliest corresponding element is returned.

      const winner = await fromAsync([1, 2, 2, 3]).mode();
      console.log(winner); // 2
    • Asynchronously returns the element that appears most frequently in the sequence, or null when the sequence is empty.

      Type Parameters

      Parameters

      • OptionalkeySelector: Selector<TElement, TKey>

        Optional selector that projects each element to the key used for frequency counting. Defaults to the element itself.

      Returns Promise<TElement | null>

      A promise that resolves to the first most frequent element, or null when the sequence contains no elements.

      Re-throws any error thrown while iterating the sequence or executing keySelector.

      Unlike mode, this overload communicates the absence of elements by resolving to null. When multiple keys share the maximum frequency, the element encountered first is returned.

      const winner = await fromAsync<number>([]).modeOrDefault();
      console.log(winner); // null
    • Produces the elements whose occurrence count is tied for the highest frequency in the async sequence.

      Type Parameters

      Parameters

      • OptionalkeySelector: Selector<TElement, TKey>

        Optional selector that projects each element to the key used for frequency counting. Defaults to the element itself.

      Returns IAsyncEnumerable<TElement>

      An async sequence containing one representative element for each frequency mode.

      Re-throws any error thrown while iterating the sequence or executing keySelector.

      The result is deferred; enumerating it buffers the entire source to compute frequency counts before yielding results. When multiple elements share a key, only the first occurrence is emitted.

      const modes = await fromAsync([1, 2, 2, 3, 3]).multimode().toArray();
      console.log(modes); // [2, 3]
    • Determines whether the async sequence contains no elements that satisfy the optional predicate.

      Parameters

      • Optionalpredicate: Predicate<TElement>

        Optional predicate evaluated against each element. When omitted, the method resolves to true if the sequence is empty.

      Returns Promise<boolean>

      A promise that resolves to true when no element satisfies the predicate (or when the sequence is empty and no predicate is provided); otherwise, false.

      This is more efficient than negating any with a predicate because iteration stops as soon as a matching element is found.

      const numbers = fromAsync([1, 3, 5]);
      const noEvens = await numbers.none(x => x % 2 === 0);
      console.log(noEvens); // true

      const mixedNumbers = fromAsync([1, 2, 3, 5]);
      const noEvens2 = await mixedNumbers.none(x => x % 2 === 0);
      console.log(noEvens2); // false
    • Returns the elements that are of the specified type. The type can be specified either as a constructor function or as a string.

      Type Parameters

      • TResult extends ObjectType

      Parameters

      • type: TResult

        The type to filter the elements of the sequence with.

      Returns IAsyncEnumerable<InferredType<TResult>>

      A new enumerable sequence whose elements are of the specified type.

      const mixed = fromAsync([1, 'two', 3, 'four', new Date()]);
      const numbers = await mixed.ofType('number').toArray();
      console.log(numbers); // [1, 3]

      const dates = await mixed.ofType(Date).toArray();
      console.log(dates); // [Date object]
    • Calculates a percentile of the numeric values produced by the async sequence.

      Parameters

      • percent: number

        Percentile expressed as a fraction between 0 and 1 where 0 corresponds to the minimum and 1 to the maximum.

      • Optionalselector: Selector<TElement, number>

        Optional projection that extracts the numeric value for each element. Defaults to treating the element itself as numeric.

      • Optionalstrategy: PercentileStrategy

        Strategy that determines how fractional ranks are resolved. Defaults to "linear", which interpolates between neighbouring values. Alternative strategies include "nearest", "low", "high", and "midpoint".

      Returns Promise<number>

      A promise that resolves to the percentile value, or NaN when the sequence contains no elements.

      Re-throws any error thrown while iterating the sequence or executing selector.

      The sequence is fully consumed and buffered so the selection algorithm can determine the requested rank without fully sorting the data. When percent is outside [0, 1], it is clamped to the bounds implied by strategy.

      const upperQuartile = await fromAsync([1, 2, 3, 4, 5]).percentile(0.75);
      console.log(upperQuartile); // 4

      const responseTimes = fromAsync([
      { endpoint: '/users', duration: 120 },
      { endpoint: '/users', duration: 80 },
      { endpoint: '/users', duration: 200 }
      ]);
      const p95 = await responseTimes.percentile(0.95, r => r.duration, "nearest");
      console.log(p95); // 200
    • Generates permutations from the distinct elements of the asynchronous sequence.

      Parameters

      • Optionalsize: number

        Optional target length for each permutation. When omitted, permutations use all distinct elements of the source.

      Returns IAsyncEnumerable<IEnumerable<TElement>>

      A lazy async sequence of permutations, each materialised as an enumerable.

      Thrown when size is less than 1 or greater than the number of distinct elements.

      The source is fully enumerated to collect distinct elements before permutations are produced. Expect combinatorial growth in the number of permutations.

      const numbers = fromAsync([1, 2, 3]);
      const perms = numbers.permutations(2);
      const result = await perms.select(p => p.toArray()).toArray();
      console.log(result); // [[1, 2], [1, 3], [2, 1], [2, 3], [3, 1], [3, 2]]
    • Applies a user-defined asynchronous pipeline to this sequence and resolves with the operator's result.

      Type Parameters

      • TResult

        Result type produced by operator.

      Parameters

      Returns Promise<TResult>

      A promise that resolves to the value produced by operator after it consumes the sequence as needed.

      Re-throws any error thrown by operator or surfaced while asynchronously enumerating the sequence.

      The operator determines when and how the sequence is consumed, enabling custom asynchronous workflows and integrations while preserving fluent syntax.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const sum = await numbers.pipe(async e => e.sum());
      console.log(sum); // 15

      const filteredAndDoubled = await numbers.pipe(async e =>
      e.where(x => x % 2 === 0).select(x => x * 2).toArray()
      );
      console.log(filteredAndDoubled); // [4, 8]
    • Returns a deferred asynchronous sequence that yields the supplied element before the source sequence.

      Parameters

      • element: TElement

        Element emitted before the original sequence.

      Returns IAsyncEnumerable<TElement>

      An async sequence that yields element followed by the source elements.

      Enumeration is deferred; the source is not iterated until the resulting sequence is consumed.

      const numbers = fromAsync([1, 2, 3]);
      const prepended = await numbers.prepend(0).toArray();
      console.log(prepended); // [0, 1, 2, 3]
    • Computes the multiplicative aggregate of the values produced for each element in the asynchronous sequence.

      Parameters

      • Optionalselector: Selector<TElement, number>

        Optional projection that extracts the numeric value for each element. Defaults to interpreting the element itself as a number.

      Returns Promise<number>

      A promise that resolves to the product of all projected values.

      Thrown when the sequence is empty.

      The source is consumed exactly once. Supply selector when elements are not already numeric.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const result = await numbers.product();
      console.log(result); // 120

      const people = fromAsync([
      { name: 'Alice', age: 25 },
      { name: 'Bob', age: 30 },
      ]);
      const ageProduct = await people.product(p => p.age);
      console.log(ageProduct); // 750
    • Returns a deferred asynchronous sequence that yields the source elements in reverse order.

      Returns IAsyncEnumerable<TElement>

      An async sequence that produces the elements of the source in reverse iteration order.

      The implementation materialises the entire sequence into an array before emitting elements, so avoid using it on infinite sequences or when memory usage is a concern.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const reversed = await numbers.reverse().toArray();
      console.log(reversed); // [5, 4, 3, 2, 1]
    • Returns a deferred asynchronous sequence that rotates the elements by the specified offset while preserving length.

      Parameters

      • shift: number

        Number of positions to rotate. Positive values move elements toward the end (left rotation); negative values move them toward the beginning (right rotation).

      Returns IAsyncEnumerable<TElement>

      An async sequence containing the same elements shifted by the requested amount.

      The source is consumed asynchronously and buffered to honour the rotation. Rotation amounts larger than the sequence length are normalised by that length, which may require buffering the full sequence.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const rotated = await numbers.rotate(2).toArray();
      console.log(rotated); // [3, 4, 5, 1, 2]

      const rotatedNegative = await numbers.rotate(-2).toArray();
      console.log(rotatedNegative); // [4, 5, 1, 2, 3]
    • Projects each element and index into an iterable and flattens the results into a single asynchronous sequence.

      Type Parameters

      • TResult

        Element type produced by the flattened iterables.

      Parameters

      Returns IAsyncEnumerable<TResult>

      An async sequence containing the concatenated contents of the iterables produced by selector.

      Each inner iterable is fully enumerated in order before the next source element is processed, preserving the relative ordering of results.

      const lists = fromAsync([[1, 2], [3, 4], [5]]);
      const flattened = await lists.selectMany(x => x).toArray();
      console.log(flattened); // [1, 2, 3, 4, 5]
    • Determines whether the asynchronous sequence and another async iterable contain equal elements in the same order.

      Parameters

      • enumerable: AsyncIterable<TElement>

        Async iterable to compare against the source sequence.

      • Optionalcomparator: EqualityComparator<TElement, TElement>

        Optional equality comparator used to compare element pairs. Defaults to the library's standard equality comparator.

      Returns Promise<boolean>

      A promise that resolves to true when both sequences have the same length and all corresponding elements are equal; otherwise, false.

      Enumeration stops as soon as a mismatch or length difference is observed. Both sequences are fully enumerated only when they are equal.

      const numbers1 = fromAsync([1, 2, 3]);
      const numbers2 = [1, 2, 3];
      const numbers3 = [1, 2, 4];

      const areEqual1 = await numbers1.sequenceEqual(numbers2);
      console.log(areEqual1); // true

      const areEqual2 = await numbers1.sequenceEqual(numbers3);
      console.log(areEqual2); // false
    • Returns a deferred asynchronous sequence whose elements appear in random order.

      Returns IAsyncEnumerable<TElement>

      An async sequence containing the same elements as the source but shuffled.

      The implementation materialises the entire sequence into an array before shuffling, making this unsuitable for infinite sequences.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const shuffled = await numbers.shuffle().toArray();
      console.log(shuffled); // e.g., [3, 1, 5, 2, 4]
    • Returns the only element that satisfies the provided type guard predicate.

      Type Parameters

      • TFiltered

        extends TElement Narrowed element type produced when predicate returns true.

      Parameters

      Returns Promise<TFiltered>

      A promise that resolves to the single element satisfying predicate.

      Thrown when the sequence is empty.

      Thrown when no element satisfies predicate.

      Thrown when more than one element satisfies predicate.

      The source is fully enumerated asynchronously to ensure exactly one matching element exists.

      const numbers = fromAsync([5]);
      const singleElement = await numbers.single();
      console.log(singleElement); // 5

      const numbers2 = fromAsync([1, 2, 3, 4, 5]);
      const singleEven = await numbers2.single(x => x > 4);
      console.log(singleEven); // 5
    • Returns the only element in the sequence or the only element that satisfies an optional predicate.

      Parameters

      • Optionalpredicate: Predicate<TElement>

        Optional predicate evaluated for each element. When provided, the result must be the unique element for which it returns true.

      Returns Promise<TElement>

      A promise that resolves to the single element in the sequence or the single element that satisfies predicate.

      Thrown when the sequence is empty.

      Thrown when more than one element exists and predicate is omitted.

      Thrown when predicate is provided and no element satisfies it.

      Thrown when predicate is provided and more than one element satisfies it.

      The source is fully enumerated asynchronously to validate uniqueness.

    • Returns the only element that satisfies the provided type guard predicate, or null when no such element exists.

      Type Parameters

      • TFiltered

        extends TElement Narrowed element type produced when predicate returns true.

      Parameters

      Returns Promise<TFiltered | null>

      A promise that resolves to the single matching element, or null when no element satisfies predicate.

      Thrown when more than one element satisfies predicate.

      The source is fully enumerated asynchronously to confirm uniqueness of the matching element.

      const numbers = fromAsync([5]);
      const singleElement = await numbers.singleOrDefault();
      console.log(singleElement); // 5

      const numbers2 = fromAsync([1, 2, 3, 4, 5]);
      const singleEven = await numbers2.singleOrDefault(x => x > 4);
      console.log(singleEven); // 5

      const empty = fromAsync<number>([]);
      const singleOfEmpty = await empty.singleOrDefault();
      console.log(singleOfEmpty); // null

      const noMatch = fromAsync([1, 2, 3]);
      const singleNoMatch = await noMatch.singleOrDefault(x => x > 4);
      console.log(singleNoMatch); // null
    • Returns the only element in the sequence or the only element that satisfies an optional predicate, or resolves to null when no such element exists.

      Parameters

      • Optionalpredicate: Predicate<TElement>

        Optional predicate evaluated for each element. When provided, the result must be the unique element for which it returns true.

      Returns Promise<TElement | null>

      A promise that resolves to the single element or matching element, or null when no element satisfies the conditions.

      Thrown when more than one element exists and predicate is omitted.

      Thrown when predicate is provided and more than one element satisfies it.

      Unlike single, this method communicates the absence of a matching element by resolving to null.

    • Skips a specified number of elements before yielding the remainder of the asynchronous sequence.

      Parameters

      • count: number

        Number of elements to bypass. Values less than or equal to zero result in no elements being skipped.

      Returns IAsyncEnumerable<TElement>

      An async sequence containing the elements that remain after skipping count items.

      Enumeration advances through the skipped prefix without yielding any of those elements.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const skipped = await numbers.skip(2).toArray();
      console.log(skipped); // [3, 4, 5]
    • Omits a specified number of elements from the end of the sequence.

      Parameters

      • count: number

        Number of trailing elements to exclude. Values less than or equal to zero leave the sequence unchanged.

      Returns IAsyncEnumerable<TElement>

      An async sequence excluding the last count elements.

      The implementation buffers up to count elements to determine which items to drop, which can increase memory usage for large counts.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const skipped = await numbers.skipLast(2).toArray();
      console.log(skipped); // [1, 2, 3]
    • Calculates the standard deviation of the numeric values produced by the async sequence.

      Parameters

      • Optionalselector: Selector<TElement, number>

        Optional projection that extracts the numeric value for each element. Defaults to the element itself.

      • Optionalsample: boolean

        When true, computes the sample standard deviation; when false, computes the population standard deviation. Defaults to true.

      Returns Promise<number>

      A promise that resolves to the calculated standard deviation, or NaN when there are insufficient values to compute it.

      Re-throws any error thrown while iterating the sequence or executing selector.

      This method delegates to variance; when the variance is NaN, that value is returned unchanged. The sequence is enumerated exactly once using a numerically stable single-pass algorithm.

      const populationStdDev = await fromAsync([1, 2, 3, 4, 5]).standardDeviation(x => x, false);
      console.log(populationStdDev); // Math.sqrt(2)
    • Returns every n-th element of the sequence, starting with the first.

      Parameters

      • step: number

        Positive interval indicating how many elements to skip between yielded items.

      Returns IAsyncEnumerable<TElement>

      An async sequence containing elements whose zero-based index is divisible by step.

      Thrown when step is less than 1.

      The source is enumerated asynchronously exactly once; elements that are not yielded are still visited to honour the stepping interval.

      const numbers = fromAsync([1, 2, 3, 4, 5, 6, 7, 8, 9]);
      const stepped = await numbers.step(3).toArray();
      console.log(stepped); // [1, 4, 7]
    • Computes the sum of the numeric values produced for each element.

      Parameters

      • Optionalselector: Selector<TElement, number>

        Optional projection that extracts the numeric value. Defaults to interpreting the element itself as a number.

      Returns Promise<number>

      A promise that resolves to the sum of the projected values.

      Thrown when the sequence is empty.

      The source is enumerated asynchronously exactly once. Supply selector when elements are not already numeric.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const total = await numbers.sum();
      console.log(total); // 15

      const people = fromAsync([
      { name: 'Alice', age: 25 },
      { name: 'Bob', age: 30 },
      ]);
      const totalAge = await people.sum(p => p.age);
      console.log(totalAge); // 55
    • Returns up to the specified number of leading elements.

      Parameters

      • count: number

        Number of elements to emit; values less than or equal to zero produce an empty sequence.

      Returns IAsyncEnumerable<TElement>

      A deferred async sequence containing at most count elements from the start of the source.

      Enumeration stops once count elements have been yielded or the source sequence ends.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const firstTwo = await numbers.take(2).toArray();
      console.log(firstTwo); // [1, 2]

      const emptyTake = await numbers.take(0).toArray();
      console.log(emptyTake); // []
    • Returns up to the specified number of trailing elements.

      Parameters

      • count: number

        Number of elements to keep from the end; values less than or equal to zero produce an empty sequence.

      Returns IAsyncEnumerable<TElement>

      A deferred async sequence containing at most count elements from the end of the source.

      The implementation buffers up to count elements to determine the tail, so memory usage grows with count. The source must be finite.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const lastTwo = await numbers.takeLast(2).toArray();
      console.log(lastTwo); // [4, 5]

      const emptyTakeLast = await numbers.takeLast(0).toArray();
      console.log(emptyTakeLast); // []
    • Invokes the specified action for each element while yielding the original elements unchanged.

      Parameters

      Returns IAsyncEnumerable<TElement>

      The original async sequence, enabling fluent chaining.

      The action executes lazily as the sequence is iterated asynchronously, making it suitable for logging or instrumentation.

      const numbers = fromAsync([1, 2, 3]);
      const tapped = await numbers
      .tap(x => console.log(`Processing: ${x}`))
      .select(x => x * 2)
      .toArray();
      console.log(tapped); // [2, 4, 6]
      // Expected console output:
      // Processing: 1
      // Processing: 2
      // Processing: 3
    • Materialises the asynchronous sequence into an array.

      Returns Promise<TElement[]>

      A promise that resolves with all elements from the source sequence in iteration order.

      The entire sequence is consumed asynchronously before the array is returned. Subsequent changes to the source are not reflected in the result.

      const numbers = fromAsync([1, 2, 3]);
      const array = await numbers.toArray();
      console.log(array); // [1, 2, 3]
    • Materialises the asynchronous sequence into a circular queue that uses the implementation's default capacity.

      Parameters

      Returns Promise<CircularQueue<TElement>>

      A promise that resolves to a circular queue containing the most recent elements from the source, up to the default capacity.

      The entire sequence is consumed asynchronously. Once the queue reaches its capacity (currently 32), older items are discarded as new elements are enqueued.

      const numbers = fromAsync([1, 2, 3]);
      const circularQueue = await numbers.toCircularQueue();
      console.log(circularQueue.toArray()); // [1, 2, 3]
    • Materialises the asynchronous sequence into a circular queue with the specified capacity.

      Parameters

      • capacity: number

        Maximum number of elements retained by the resulting queue.

      • Optionalcomparator: EqualityComparator<TElement, TElement>

        Optional equality comparator used by the resulting queue.

      Returns Promise<CircularQueue<TElement>>

      A promise that resolves to a circular queue containing the most recent elements from the source, bounded by capacity.

      The entire sequence is consumed asynchronously. When the source contains more than capacity elements, earlier items are discarded.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const circularQueue = await numbers.toCircularQueue(3);
      console.log(circularQueue.toArray()); // [3, 4, 5]
    • Materialises the asynchronous sequence into an enumerable set containing the distinct elements.

      Returns Promise<EnumerableSet<TElement>>

      A promise that resolves to a set populated with the distinct elements from the source.

      The entire sequence is consumed asynchronously before the set is returned, and duplicate elements are collapsed using the set's equality semantics.

      const numbers = fromAsync([1, 2, 2, 3, 1]);
      const set = await numbers.toEnumerableSet();
      console.log(set.toArray()); // [1, 2, 3]
    • Materialises the asynchronous sequence into an immutable set containing the distinct elements.

      Returns Promise<ImmutableSet<TElement>>

      A promise that resolves to an immutable set built from the distinct elements of the source.

      The entire sequence is consumed asynchronously before the set is returned, and duplicate elements are collapsed using the set's equality semantics.

      const numbers = fromAsync([1, 2, 2, 3, 1]);
      const immutableSet = await numbers.toImmutableSet();
      console.log(immutableSet.toArray()); // [1, 2, 3]
    • Materialises the asynchronous sequence into a lookup keyed by the provided selector.

      Type Parameters

      Parameters

      Returns Promise<ILookup<TKey, TValue>>

      A promise that resolves to a lookup grouping the projected values by key.

      The entire sequence is consumed asynchronously. Elements within each group preserve their original order and the groups are cached for repeated enumeration.

      const products = fromAsync([
      { name: 'Apple', category: 'Fruit' },
      { name: 'Banana', category: 'Fruit' },
      { name: 'Carrot', category: 'Vegetable' },
      ]);
      const lookup = await products.toLookup(p => p.category, p => p.name);
      console.log(lookup.get('Fruit').toArray()); // ['Apple', 'Banana']
      console.log(lookup.get('Vegetable').toArray()); // ['Carrot']
    • Materialises the asynchronous sequence into a Map keyed by the provided selector.

      Type Parameters

      Parameters

      Returns Promise<Map<TKey, TValue>>

      A promise that resolves to a map populated with the projected key/value pairs.

      The entire sequence is consumed asynchronously. When keySelector produces duplicate keys, later elements overwrite earlier entries.

      const people = fromAsync([
      { id: 1, name: 'Alice' },
      { id: 2, name: 'Bob' },
      ]);
      const map = await people.toMap(p => p.id, p => p.name);
      console.log(map.get(1)); // 'Alice'
      console.log(map.get(2)); // 'Bob'
    • Materialises the asynchronous sequence into a plain object keyed by the provided selector.

      Type Parameters

      • TKey extends PropertyKey

        extends string | number | symbol Property key type returned by keySelector.

      • TValue

        Type of value returned by valueSelector.

      Parameters

      Returns Promise<Record<TKey, TValue>>

      A promise that resolves to an object populated with the projected key/value pairs.

      The entire sequence is consumed asynchronously. When keySelector produces duplicate keys, later values overwrite earlier ones.

      const people = fromAsync([
      { id: 1, name: 'Alice' },
      { id: 2, name: 'Bob' },
      ]);
      const obj = await people.toObject(p => p.id, p => p.name);
      console.log(obj[1]); // 'Alice'
      console.log(obj[2]); // 'Bob'
    • Materialises the asynchronous sequence into a native Set.

      Returns Promise<Set<TElement>>

      A promise that resolves to a set containing the distinct elements from the source.

      The entire sequence is consumed asynchronously before the set is returned, and duplicate elements are collapsed using JavaScript's SameValueZero semantics.

      const numbers = fromAsync([1, 2, 2, 3, 1]);
      const set = await numbers.toSet();
      console.log(Array.from(set)); // [1, 2, 3]
    • Materialises the asynchronous sequence into a sorted set of distinct elements.

      Parameters

      Returns Promise<SortedSet<TElement>>

      A promise that resolves to a sorted set containing the distinct elements from the source.

      The entire sequence is consumed asynchronously before the set is returned, and duplicate elements are collapsed using the set's ordering semantics.

      const numbers = fromAsync([3, 1, 4, 1, 5, 9, 2, 6]);
      const sortedSet = await numbers.toSortedSet();
      console.log(sortedSet.toArray()); // [1, 2, 3, 4, 5, 6, 9]
    • Creates a set-style union between this asynchronous sequence and enumerable using an equality comparator.

      Parameters

      • enumerable: AsyncIterable<TElement>

        Additional asynchronous sequence whose elements are consumed after the source when forming the union.

      • Optionalcomparator: EqualityComparator<TElement, TElement>

        Optional equality comparator that determines whether two elements are considered the same. Defaults to the library's standard equality comparator.

      Returns IAsyncEnumerable<TElement>

      A deferred asynchronous sequence containing the distinct elements from this sequence followed by elements from enumerable that are not already present according to comparator.

      Re-throws any error thrown while iterating either async sequence or executing comparator.

      Elements from the original sequence always appear before contributions from enumerable. The method buffers only the comparison data needed to detect duplicates and consumes each input at most once.

      const numbers1 = fromAsync([1, 2, 3, 4, 5]);
      const numbers2 = [3, 5, 6, 7];
      const unioned = await numbers1.union(numbers2).toArray();
      console.log(unioned); // [1, 2, 3, 4, 5, 6, 7]
    • Creates a set-style union between this asynchronous sequence and enumerable by comparing keys projected from each element.

      Type Parameters

      Parameters

      • enumerable: AsyncIterable<TElement>

        Additional asynchronous sequence whose elements are consumed after the source when forming the union.

      • keySelector: Selector<TElement, TKey>

        Projection that produces a comparison key for each element.

      • Optionalcomparator: EqualityComparator<TKey, TKey>

        Optional equality comparator that determines whether two keys are considered the same. Defaults to the library's standard equality comparator.

      Returns IAsyncEnumerable<TElement>

      A deferred asynchronous sequence containing the distinct elements from this sequence followed by elements from enumerable whose keys were not previously observed.

      Re-throws any error thrown while iterating either async sequence or executing keySelector or comparator.

      Keys are buffered to ensure uniqueness while elements remain streamable. Provide comparator when keys require structural equality semantics.

      const products1 = fromAsync([
      { name: 'Apple', category: 'Fruit' },
      { name: 'Banana', category: 'Fruit' },
      ]);
      const products2 = [
      { name: 'Carrot', category: 'Vegetable' },
      { name: 'Apple', category: 'Fruit' },
      ];

      const unioned = await products1.unionBy(products2, p => p.category).toArray();
      console.log(unioned);
      // [
      // { name: 'Apple', category: 'Fruit' },
      // { name: 'Banana', category: 'Fruit' },
      // { name: 'Carrot', category: 'Vegetable' }
      // ]
    • Calculates the variance of the numeric values produced by the async sequence.

      Parameters

      • Optionalselector: Selector<TElement, number>

        Optional projection that extracts the numeric value for each element. Defaults to the element itself.

      • Optionalsample: boolean

        When true, computes the sample variance dividing by n - 1; when false, computes the population variance dividing by n. Defaults to true.

      Returns Promise<number>

      A promise that resolves to the calculated variance, or NaN when the sequence is empty—or for sample variance when it contains a single element.

      Re-throws any error thrown while iterating the sequence or executing selector.

      A numerically stable single-pass algorithm (Welford's method) is used, so the sequence is enumerated exactly once regardless of size.

      const sampleVariance = await fromAsync([1, 2, 3, 4, 5]).variance();
      console.log(sampleVariance); // 2.5
    • Produces an asynchronous sequence of sliding windows of fixed size over the source sequence.

      Parameters

      • size: number

        Length of each window; must be at least 1.

      Returns IAsyncEnumerable<IEnumerable<TElement>>

      A deferred async sequence where each element exposes one contiguous window from the source.

      Thrown when size is less than 1.

      Re-throws any error thrown while asynchronously iterating the source sequence.

      Windows overlap and are yielded only after enough source elements are observed to fill size. Trailing partial windows are omitted.

      const numbers = fromAsync([1, 2, 3, 4, 5]);
      const windows = numbers.windows(3);
      const result = await windows.select(w => w.toArray()).toArray();
      console.log(result); // [[1, 2, 3], [2, 3, 4], [3, 4, 5]]
    • Combines this asynchronous sequence with iterable and yields tuples of aligned elements.

      Type Parameters

      • TSecond

        Type of elements produced by iterable.

      Parameters

      • iterable: AsyncIterable<TSecond>

        The secondary async sequence whose elements are paired with the source elements.

      Returns IAsyncEnumerable<[TElement, TSecond]>

      A deferred async sequence of [source, other] tuples truncated to the length of the shorter input.

      Re-throws any error thrown while iterating either async sequence.

      Enumeration is lazy; pairs are produced on demand and iteration stops when either sequence completes. Use the overload that accepts a zipper when you need to project custom results.

      const numbers = fromAsync([1, 2, 3]);
      const letters = fromAsync(['a', 'b', 'c']);
      const zipped = await numbers.zip(letters).toArray();
      console.log(zipped); // [[1, 'a'], [2, 'b'], [3, 'c']]

      const zippedWithSelector = await numbers.zip(letters, (num, letter) => `${num}-${letter}`).toArray();
      console.log(zippedWithSelector); // ['1-a', '2-b', '3-c']
    • Combines this asynchronous sequence with iterable and projects each aligned pair using zipper.

      Type Parameters

      Parameters

      • iterable: AsyncIterable<TSecond>

        The secondary async sequence whose elements are paired with the source elements.

      • zipper: Zipper<TElement, TSecond, TResult>

        Projection invoked with each [source, other] pair to produce the resulting element. When omitted, the overload returning tuples should be used instead.

      Returns IAsyncEnumerable<TResult>

      A deferred async sequence of projected results truncated to the length of the shorter input.

      Re-throws any error thrown while iterating either async sequence or executing the zipper function.

      Enumeration is lazy; the zipper function executes on demand for each pair and iteration stops when either sequence completes.

    • Zips this async sequence with the iterables supplied in iterables, producing aligned tuples.

      Type Parameters

      • TIterable extends readonly AsyncIterable<unknown, any, any>[]

        Extends readonly AsyncIterable<unknown>[]; the element type of each iterable contributes to the resulting tuple.

      Parameters

      • ...iterables: [...TIterable[]]

        Additional async iterables to zip with the source.

      Returns IAsyncEnumerable<[TElement, ...UnpackAsyncIterableTuple<TIterable>[]]>

      A deferred async sequence of tuples truncated to the length of the shortest input.

      Re-throws any error raised while iterating the source or any of the supplied async iterables.

      Iteration stops as soon as any participating async iterable completes. Tuple element types are inferred from the supplied iterables, preserving strong typing across the zipped result.

      const zipped = await fromAsync([1, 2, 3]).zipMany(
      fromAsync(['A', 'B', 'C']),
      fromAsync([true, false])
      ).toArray();
      console.log(zipped); // [[1, 'A', true], [2, 'B', false]]
    • Zips this async sequence with the iterables supplied in iterablesAndZipper and projects each tuple with ZipManyZipper zipper.

      Type Parameters

      • TIterable extends readonly AsyncIterable<unknown, any, any>[]

        Extends readonly AsyncIterable<unknown>[]; the element type of each iterable contributes to the zipper input tuple.

      • TResult

        Result type produced by ZipManyZipper zipper.

      Parameters

      • ...iterablesAndZipper: [
            ...TIterable[],
            ZipManyZipper<
                [TElement, ...UnpackAsyncIterableTuple<TIterable>[]],
                TResult,
            >,
        ]

        The trailing argument may be a zipper invoked with each tuple to produce a projected result; preceding arguments are the async iterables to zip with.

      Returns IAsyncEnumerable<TResult>

      A deferred async sequence of projected results truncated to the length of the shortest input.

      Re-throws any error raised while iterating the source, the supplied async iterables, or executing the zipper.

      The zipper receives a readonly tuple [source, ...others] for each aligned set. Iteration stops as soon as any participating async iterable completes.

      const labels = await fromAsync([1, 2, 3]).zipMany(
      fromAsync(['A', 'B', 'C']),
      fromAsync([true, true, false]),
      ([num, letter, flag]) => `${num}${letter}-${flag ? "yes" : "no"}`
      ).toArray();
      console.log(labels); // ["1A-yes", "2B-yes", "3C-no"]