/** * @module Collection */ import { type StandardSchemaV1 } from "@standard-schema/spec"; import { type Collapse, type Comparator, type PredicateInvocable, type ForEach, type ICollection, type Map, type Modifier, type Tap, type Transform, type Reduce, type CrossJoinResult, type EnsureMap, type EnsureRecord, type SerializedCollection } from "../../../collection/contracts/_module.js"; import { type IterableValue, type Lazyable } from "../../../utilities/_module.js"; /** * All methods that return {@link ICollection | `ICollection`} are executed lazly, meaning the execution will occur iterating the items withthe `forEach` method or `for of` loop. * * IMPORT_PATH: `"@daiso-tech/core/collection"` * @group Implementations */ export declare class IterableCollection implements ICollection { /** * The `concat` static method is a convenient utility for easily concatenating multiple {@link Iterable | `Iterable`}. * @example * ```ts * import { IterableCollection } from "@daiso-tech/core/collection"; * * class MyIterable implements Iterable { * *[Symbol.iterator](): Iterator { * yield 1; * yield 2; * yield 3; * } * } * * const collection = IterableCollection.concat([ * new MyIterable(), * new Set([1, 2, 3]), * new Map([["a", 1], ["b", 2]]), * ["a", "b", "c"] * ]); * collection.toArray(); * // [1, 2, 3, 1, 2, 3, ["a", 1], ["b", 2], "a", "b", "c"] * ``` */ static concat(iterables: IterableValue>): ICollection; /** * 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 { IterableCollection } from "@daiso-tech/core/collection"; * * const collection = IterableCollection.difference( * [1, 2, 2, 3, 4, 5], * [2, 4, 6, 8] * ); * collection.toArray(); * // [1, 3, 5] * ``` * @example * ```ts * import { IterableCollection } from "@daiso-tech/core/collection"; * * const collection = IterableCollection.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 * ); * 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: IterableValue, iterableB: IterableValue, selectFn?: Map, TSelect>): ICollection; /** * 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 { IterableCollection } from "@daiso-tech/core/collection"; * * const collection = IterableCollection.zip(["Chair", "Desk"], [100, 200]); * collection.toArray(); * // [["Chair", 100], ["Desk", 200]] * ``` * @example * ```ts * import { IterableCollection } from "@daiso-tech/core/collection"; * * const collection = IterableCollection.zip(["Chair", "Desk", "Couch"], [100, 200]); * collection.toArray(); * // [["Chair", 100], ["Desk", 200]] * ``` * @example * ```ts * import { IterableCollection } from "@daiso-tech/core/collection"; * * const collection = IterableCollection.zip(["Chair", "Desk"], [100, 200, 300]); * collection.toArray(); * // [["Chair", 100], ["Desk", 200]] * ``` */ static zip(iterableA: IterableValue, iterableB: IterableValue): ICollection<[TValueA, TValueB]>; static deserialize(serializedValue: SerializedCollection): ICollection; private static DEFAULT_CHUNK_SIZE; private static makeCollection; private readonly iterable; /** * The `constructor` takes an {@link Iterable | `Iterable`}. * * Works with `Array`. * @example * ```ts * import { IterableCollection } from "@daiso-tech/core/collection"; * * const collection = new IterableCollection([1, 2, 3, 4]); * ``` * * Works with `String`. * @example * ```ts * import { IterableCollection } from "@daiso-tech/core/collection"; * * const collection = new IterableCollection("ABCDE"); * ``` * * Works with `Set`. * @example * ```ts * import { IterableCollection } from "@daiso-tech/core/collection"; * * const collection = new IterableCollection(new Set([1, 2, 2 4])); * ``` * * Works with `Map`. * @example * ```ts * import { IterableCollection } from "@daiso-tech/core/collection"; * * const collection = new IterableCollection(new Map([["a", 1], ["b", 2]])); * ``` * * Works with any `Iterable`. * @example * ```ts * import { IterableCollection } from "@daiso-tech/core/collection"; * * class MyIterable implements Iterable { * *[Symbol.iterator](): Iterator { * yield 1; * yield 2; * yield 3; * } * } * const collection = new IterableCollection(new MyIterable()); * ``` */ constructor(iterable: IterableValue); serialize(): SerializedCollection; [Symbol.iterator](): Iterator; toIterator(): Iterator; entries(): ICollection<[number, TInput]>; keys(): ICollection; copy(): ICollection; filter(predicateFn: PredicateInvocable, TOutput>): ICollection; validate(schema: StandardSchemaV1): ICollection; reject(predicateFn: PredicateInvocable, TOutput>): ICollection>; map(mapFn: Map, TOutput>): ICollection; reduce(reduceFn: Reduce, TInput>): TInput; reduce(reduceFn: Reduce, TInput>, initialValue: TInput): TInput; reduce(reduceFn: Reduce, TOutput>, initialValue: TOutput): TOutput; join(separator?: string): Extract; collapse(): ICollection>; flatMap(mapFn: Map, Iterable>): ICollection; change(predicateFn: PredicateInvocable, TFilterOutput>, mapFn: Map, TMapOutput>): ICollection; set(index: number, value: TInput | Map, TInput>): ICollection; get(index: number): TInput | null; getOrFail(index: number): TInput; page(page: number, pageSize: number): ICollection; sum(): Extract; average(): Extract; median(): Extract; min(): Extract; max(): Extract; percentage(predicateFn: PredicateInvocable>): number; some(predicateFn: PredicateInvocable, TOutput>): boolean; every(predicateFn: PredicateInvocable, TOutput>): boolean; take(limit: number): ICollection; takeUntil(predicateFn: PredicateInvocable>): ICollection; takeWhile(predicateFn: PredicateInvocable>): ICollection; skip(offset: number): ICollection; skipUntil(predicateFn: PredicateInvocable>): ICollection; skipWhile(predicateFn: PredicateInvocable, TOutput>): ICollection; when(condition: boolean, callback: Modifier, ICollection>): ICollection; whenEmpty(callback: Modifier, ICollection>): ICollection; whenNot(condition: boolean, callback: Modifier, ICollection>): ICollection; whenNotEmpty(callback: Modifier, ICollection>): ICollection; pipe(callback: Transform, TOutput>): TOutput; tap(callback: Tap>): ICollection; chunk(chunkSize: number): ICollection>; chunkWhile(predicateFn: PredicateInvocable>): ICollection>; split(chunkAmount: number): ICollection>; partition(predicateFn: PredicateInvocable>): ICollection>; sliding(chunkSize: number, step?: number): ICollection>; groupBy(selectFn?: Map, TOutput>): ICollection<[TOutput, ICollection]>; countBy(selectFn?: Map, TOutput>): ICollection<[TOutput, number]>; unique(selectFn?: Map, TOutput>): ICollection; difference(iterable: IterableValue, mapFn?: Map, TOutput>): ICollection; repeat(amount: number): ICollection; padStart(maxLength: number, fillItems: IterableValue): ICollection; padEnd(maxLength: number, fillItems: IterableValue): ICollection; slice(start?: number, end?: number): ICollection; prepend(iterable: IterableValue): ICollection; append(iterable: IterableValue): ICollection; insertBefore(predicateFn: PredicateInvocable>, iterable: IterableValue): ICollection; insertAfter(predicateFn: PredicateInvocable>, iterable: IterableValue): ICollection; crossJoin(iterable: IterableValue): ICollection>; zip(iterable: IterableValue): ICollection<[TInput, TExtended]>; sort(comparator?: Comparator): ICollection; reverse(chunkSize?: number): ICollection; shuffle(mathRandom?: () => number): ICollection; private first_; first(predicateFn?: PredicateInvocable, TOutput>): TOutput | null; firstOr(defaultValue: Lazyable, predicateFn?: PredicateInvocable, TOutput>): TOutput | TExtended; firstOrFail(predicateFn?: PredicateInvocable, TOutput>): TOutput; private last_; last(predicateFn?: PredicateInvocable, TOutput>): TOutput | null; lastOr(defaultValue: Lazyable, predicateFn?: PredicateInvocable, TOutput>): TOutput | TExtended; lastOrFail(predicateFn?: PredicateInvocable, TOutput>): TOutput; private before_; before(predicateFn?: PredicateInvocable, TOutput>): TOutput | null; beforeOr(defaultValue: Lazyable, predicateFn?: PredicateInvocable, TOutput>): TOutput | TExtended; beforeOrFail(predicateFn?: PredicateInvocable, TOutput>): TOutput; private after_; after(predicateFn?: PredicateInvocable, TOutput>): TOutput | null; afterOr(defaultValue: Lazyable, predicateFn?: PredicateInvocable, TOutput>): TOutput | TExtended; afterOrFail(predicateFn?: PredicateInvocable, TOutput>): TOutput; sole(predicateFn: PredicateInvocable, TOutput>): TOutput; nth(step: number): ICollection; count(predicateFn: PredicateInvocable>): number; size(): number; isEmpty(): boolean; isNotEmpty(): boolean; searchFirst(predicateFn: PredicateInvocable>): number; searchLast(predicateFn: PredicateInvocable>): number; forEach(callback: ForEach>): void; toArray(): Array; toRecord(): EnsureRecord; toMap(): EnsureMap; }