/** * @module Collection */ import { type StandardSchemaV1 } from "@standard-schema/spec"; import { type AsyncCollapse, type AsyncPredicate, type AsyncForEach, type AsyncMap, type AsyncModifier, type AsyncTap, type AsyncTransform, type Comparator, type IAsyncCollection, type AsyncReduce, type CrossJoinResult, type EnsureMap, type EnsureRecord } from "../../../collection/contracts/_module.js"; import { type AsyncIterableValue, type AsyncLazyable } from "../../../utilities/_module.js"; /** * All methods that return {@link IAsyncCollection | `IAsyncCollection`} are executed lazly, meaning the execution will occur iterating the items withthe `forEach` method or `for await` loop. * * IMPORT_PATH: `"@daiso-tech/core/collection"` * @group Implementations */ export declare class AsyncIterableCollection implements IAsyncCollection { /** * The `concat` static method is a convenient utility for easily concatenating multiple {@link Iterable | `Iterable`} or {@link AsyncIterable | `AsyncIterable`}. * @example * ```ts * import { AsyncIterableCollection } from "@daiso-tech/core/collection"; * * class MyAsyncIterable implements AsyncIterable { * async *[Symbol.iterator](): Iterator { * yield "a"; * yield "b"; * yield "c"; * } * } * * class MyIterable implements Iterable { * *[Symbol.iterator](): Iterator { * yield 1; * yield 2; * yield 3; * } * } * * const collection = AsyncIterableCollection.concat([ * new MyAsyncIterable(), * new MyIterable(), * new Set([1, 2, 3]), * new Map([["a", 1], ["b", 2]]), * ["a", "b", "c"] * ]); * await collection.toArray(); * // ["a", "b", "c", 1, 2, 3, 1, 2, 3, ["a", 1], ["b", 2], "a", "b", "c"] * ``` */ static concat(iterables: AsyncIterableValue>): IAsyncCollection; /** * The `difference` static method is used to compute the difference between two {@link Iterable | `Iterable`} instances. By default, the equality check is performed on each item. * @example * ```ts * import { AsyncIterableCollection } from "@daiso-tech/core/collection"; * * const collection = AsyncIterableCollection.difference( * [1, 2, 2, 3, 4, 5], * [2, 4, 6, 8] * ); * await collection.toArray(); * // [1, 3, 5] * ``` * @example * ```ts * import { AsyncIterableCollection } from "@daiso-tech/core/collection"; * * const collection = AsyncIterableCollection.difference( * [ * { name: "iPhone 6", brand: "Apple", type: "phone" }, * { name: "iPhone 5", brand: "Apple", type: "phone" }, * { name: "Apple Watch", brand: "Apple", type: "watch" }, * { name: "Galaxy S6", brand: "Samsung", type: "phone" }, * { name: "Galaxy Gear", brand: "Samsung", type: "watch" }, * ], * [ * { name: "Apple Watch", brand: "Apple", type: "watch" }, * ], * (product) => product.type * ); * await collection.toArray(); * // [ * // { name: "iPhone 6", brand: "Apple", type: "phone" }, * // { name: "iPhone 5", brand: "Apple", type: "phone" }, * // { name: "Galaxy S6", brand: "Samsung", type: "phone" }, * // ] * ``` */ static difference(iterableA: AsyncIterableValue, iterableB: AsyncIterableValue, selectFn?: AsyncMap, TSelect>): IAsyncCollection; /** * The `zip` static method merges together the values of `iterableA` with the values of the `iterableB` at their corresponding index. * The returned collection has size of the shortest collection. * @example * ```ts * import { AsyncIterableCollection } from "@daiso-tech/core/collection"; * * const collection = AsyncIterableCollection.zip(["Chair", "Desk"], [100, 200]); * await collection.toArray(); * // [["Chair", 100], ["Desk", 200]] * ``` * @example * ```ts * import { AsyncIterableCollection } from "@daiso-tech/core/collection"; * * const collection = AsyncIterableCollection.zip(["Chair", "Desk", "Couch"], [100, 200]); * await collection.toArray(); * // [["Chair", 100], ["Desk", 200]] * ``` * @example * ```ts * import { AsyncIterableCollection } from "@daiso-tech/core/collection"; * * const collection = AsyncIterableCollection.zip(["Chair", "Desk"], [100, 200, 300]); * await collection.toArray(); * // [["Chair", 100], ["Desk", 200]] * ``` */ static zip(iterableA: AsyncIterableValue, iterableB: AsyncIterableValue): IAsyncCollection<[TValueA, TValueB]>; private static DEFAULT_CHUNK_SIZE; private static makeCollection; private readonly iterable; /** * The `constructor` takes an {@link Iterable | `Iterable`} or {@link AsyncIterable | `AsyncIterable`}. * * Works with `Array`. * @example * ```ts * import { AsyncIterableCollection } from "@daiso-tech/core/collection"; * * const collection = new AsyncIterableCollection([1, 2, 3, 4]); * ``` * * Works with `String`. * @example * ```ts * import { AsyncIterableCollection } from "@daiso-tech/core/collection"; * * const collection = new AsyncIterableCollection("ABCDE"); * ``` * * Works with `Set`. * @example * ```ts * import { AsyncIterableCollection } from "@daiso-tech/core/collection"; * * const collection = new AsyncIterableCollection(new Set([1, 2, 2 4])); * ``` * * Works with `Map`. * @example * ```ts * import { AsyncIterableCollection } from "@daiso-tech/core/collection"; * * const collection = new AsyncIterableCollection(new Map([["a", 1], ["b", 2]])); * ``` * * Works with any `Iterable`. * @example * ```ts * import { AsyncIterableCollection } from "@daiso-tech/core/collection"; * * class MyIterable implements Iterable { * *[Symbol.iterator](): Iterator { * yield 1; * yield 2; * yield 3; * } * } * const collection = new AsyncIterableCollection(new MyIterable()); * ``` * * Works with any `AsyncIterable`. * @example * ```ts * import { AsyncIterableCollection } from "@daiso-tech/core/collection"; * * class MyIterable implements AsyncIterable { * async *[Symbol.iterator](): Iterator { * yield 1; * yield 2; * yield 3; * } * } * const collection = new AsyncIterableCollection(new MyIterable()); * ``` */ constructor(iterable?: AsyncIterableValue); [Symbol.asyncIterator](): AsyncIterator; toIterator(): AsyncIterator; entries(): IAsyncCollection<[number, TInput]>; keys(): IAsyncCollection; copy(): IAsyncCollection; filter(predicateFn: AsyncPredicate, TOutput>): IAsyncCollection; validate(schema: StandardSchemaV1): IAsyncCollection; reject(predicateFn: AsyncPredicate, TOutput>): IAsyncCollection>; map(mapFn: AsyncMap, TOutput>): IAsyncCollection; reduce(reduce: AsyncReduce, TInput>): Promise; reduce(reduce: AsyncReduce, TInput>, initialValue: TInput): Promise; reduce(reduce: AsyncReduce, TOutput>, initialValue: Promise): Promise; join(separator?: string): Promise>; collapse(): IAsyncCollection>; flatMap(mapFn: AsyncMap, Iterable>): IAsyncCollection; change(predicateFn: AsyncPredicate, TFilterOutput>, mapFn: AsyncMap, TMapOutput>): IAsyncCollection; set(index: number, value: TInput | AsyncMap, TInput>): IAsyncCollection; get(index: number): Promise; getOrFail(index: number): Promise; page(page: number, pageSize: number): IAsyncCollection; sum(): Promise>; average(): Promise>; median(): Promise>; min(): Promise>; max(): Promise>; percentage(predicateFn: AsyncPredicate>): Promise; some(predicateFn: AsyncPredicate, TOutput>): Promise; every(predicateFn: AsyncPredicate, TOutput>): Promise; take(limit: number): IAsyncCollection; takeUntil(predicateFn: AsyncPredicate>): IAsyncCollection; takeWhile(predicateFn: AsyncPredicate>): IAsyncCollection; skip(offset: number): IAsyncCollection; skipUntil(predicateFn: AsyncPredicate>): IAsyncCollection; skipWhile(predicateFn: AsyncPredicate>): IAsyncCollection; when(condition: boolean, callback: AsyncModifier, IAsyncCollection>): IAsyncCollection; whenEmpty(callback: AsyncModifier, IAsyncCollection>): IAsyncCollection; whenNot(condition: boolean, callback: AsyncModifier, IAsyncCollection>): IAsyncCollection; whenNotEmpty(callback: AsyncModifier, IAsyncCollection>): IAsyncCollection; pipe(callback: AsyncTransform, TOutput>): Promise; tap(callback: AsyncTap>): IAsyncCollection; chunk(chunkSize: number): IAsyncCollection>; chunkWhile(predicateFn: AsyncPredicate>): IAsyncCollection>; split(chunkAmount: number): IAsyncCollection>; partition(predicateFn: AsyncPredicate>): IAsyncCollection>; sliding(chunkSize: number, step?: number): IAsyncCollection>; groupBy(selectFn?: AsyncMap, TOutput>): IAsyncCollection<[TOutput, IAsyncCollection]>; countBy(selectFn?: AsyncMap, TOutput>): IAsyncCollection<[TOutput, number]>; unique(selectFn?: AsyncMap, TOutput>): IAsyncCollection; difference(iterable: AsyncIterableValue, selectFn?: AsyncMap, TOutput>): IAsyncCollection; repeat(amount: number): IAsyncCollection; padStart(maxLength: number, fillItems: AsyncIterableValue): IAsyncCollection; padEnd(maxLength: number, fillItems: AsyncIterableValue): IAsyncCollection; slice(start?: number, end?: number): IAsyncCollection; prepend(iterable: AsyncIterableValue): IAsyncCollection; append(iterable: AsyncIterableValue): IAsyncCollection; insertBefore(predicateFn: AsyncPredicate>, iterable: AsyncIterableValue): IAsyncCollection; insertAfter(predicateFn: AsyncPredicate>, iterable: AsyncIterableValue): IAsyncCollection; crossJoin(iterable: AsyncIterableValue): IAsyncCollection>; zip(iterable: AsyncIterableValue): IAsyncCollection<[TInput, TExtended]>; sort(comparator?: Comparator): IAsyncCollection; reverse(chunkSize?: number): IAsyncCollection; shuffle(mathRandom?: () => number): IAsyncCollection; private first_; first(predicateFn?: AsyncPredicate, TOutput>): Promise; firstOr(defaultValue: AsyncLazyable, predicateFn?: AsyncPredicate, TOutput>): Promise; firstOrFail(predicateFn?: AsyncPredicate, TOutput>): Promise; private last_; last(predicateFn?: AsyncPredicate, TOutput>): Promise; lastOr(defaultValue: AsyncLazyable, predicateFn?: AsyncPredicate, TOutput>): Promise; lastOrFail(predicateFn?: AsyncPredicate, TOutput>): Promise; private before_; before(predicateFn?: AsyncPredicate, TOutput>): Promise; beforeOr(defaultValue: AsyncLazyable, predicateFn?: AsyncPredicate, TOutput>): Promise; beforeOrFail(predicateFn?: AsyncPredicate, TOutput>): Promise; private after_; after(predicateFn?: AsyncPredicate, TOutput>): Promise; afterOr(defaultValue: AsyncLazyable, predicateFn?: AsyncPredicate, TOutput>): Promise; afterOrFail(predicateFn?: AsyncPredicate, TOutput>): Promise; sole(predicateFn: AsyncPredicate, TOutput>): Promise; nth(step: number): IAsyncCollection; count(predicateFn: AsyncPredicate>): Promise; size(): Promise; isEmpty(): Promise; isNotEmpty(): Promise; searchFirst(predicateFn: AsyncPredicate>): Promise; searchLast(predicateFn: AsyncPredicate>): Promise; forEach(callback: AsyncForEach>): Promise; toArray(): Promise>; toRecord(): Promise>; toMap(): Promise>; }