Type Alias IAsyncCollection<TInput>

IAsyncCollection<TInput>: AsyncIterable<TInput> & {
    after(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): LazyPromise<null | TInput>;
    afterOr<TExtended>(defaultValue: AsyncLazyable<TExtended>, predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): LazyPromise<TInput | TExtended>;
    afterOrFail(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): LazyPromise<TInput>;
    append<TExtended>(iterable: AsyncIterableValue<TInput | TExtended>): IAsyncCollection<TInput | TExtended>;
    average(): LazyPromise<Extract<TInput, number>>;
    before(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): LazyPromise<null | TInput>;
    beforeOr<TExtended>(defaultValue: AsyncLazyable<TExtended>, predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): LazyPromise<TInput | TExtended>;
    beforeOrFail(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): LazyPromise<TInput>;
    change<TFilterOutput, TMapOutput>(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>, TFilterOutput>, mapFn: AsyncMap<TFilterOutput, IAsyncCollection<TInput>, TMapOutput>): IAsyncCollection<TInput | TFilterOutput | TMapOutput>;
    chunk(chunkSize: number): IAsyncCollection<IAsyncCollection<TInput>>;
    chunkWhile(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): IAsyncCollection<IAsyncCollection<TInput>>;
    collapse(): IAsyncCollection<AsyncCollapse<TInput>>;
    count(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): LazyPromise<number>;
    countBy<TOutput>(selectFn?: AsyncMap<TInput, IAsyncCollection<TInput>, TOutput>): IAsyncCollection<[TOutput, number]>;
    crossJoin<TExtended>(iterable: AsyncIterableValue<TExtended>): IAsyncCollection<CrossJoinResult<TInput, TExtended>>;
    delay(time: TimeSpan): IAsyncCollection<TInput>;
    difference<TOutput>(iterable: AsyncIterableValue<TInput>, selectFn?: AsyncMap<TInput, IAsyncCollection<TInput>, TOutput>): IAsyncCollection<TInput>;
    entries(): IAsyncCollection<[number, TInput]>;
    every<TOutput>(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>, TOutput>): LazyPromise<boolean>;
    filter<TOutput>(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>, TOutput>): IAsyncCollection<TOutput>;
    first<TOutput>(predicateFn?: AsyncPredicate<TInput, IAsyncCollection<TInput>, TOutput>): LazyPromise<null | TOutput>;
    firstOr<TOutput, TExtended>(defaultValue: AsyncLazyable<TExtended>, predicateFn?: AsyncPredicate<TInput, IAsyncCollection<TInput>, TOutput>): LazyPromise<TOutput | TExtended>;
    firstOrFail<TOutput>(predicateFn?: AsyncPredicate<TInput, IAsyncCollection<TInput>, TOutput>): LazyPromise<TOutput>;
    flatMap<TOutput>(mapFn: AsyncMap<TInput, IAsyncCollection<TInput>, Iterable<TOutput, any, any>>): IAsyncCollection<TOutput>;
    forEach(callback: AsyncForEach<TInput, IAsyncCollection<TInput>>): LazyPromise<void>;
    get(index: number): LazyPromise<null | TInput>;
    getOrFail(index: number): LazyPromise<TInput>;
    groupBy<TOutput>(selectFn?: AsyncMap<TInput, IAsyncCollection<TInput>, TOutput>): IAsyncCollection<[TOutput, IAsyncCollection<TInput>]>;
    insertAfter<TExtended>(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>, iterable: AsyncIterableValue<TInput | TExtended>): IAsyncCollection<TInput | TExtended>;
    insertBefore<TExtended>(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>, iterable: AsyncIterableValue<TInput | TExtended>): IAsyncCollection<TInput | TExtended>;
    isEmpty(): LazyPromise<boolean>;
    isNotEmpty(): LazyPromise<boolean>;
    join(separator?: string): LazyPromise<Extract<TInput, string>>;
    keys(): IAsyncCollection<number>;
    last<TOutput>(predicateFn?: AsyncPredicate<TInput, IAsyncCollection<TInput>, TOutput>): LazyPromise<null | TOutput>;
    lastOr<TOutput, TExtended>(defaultValue: AsyncLazyable<TExtended>, predicateFn?: AsyncPredicate<TInput, IAsyncCollection<TInput>, TOutput>): LazyPromise<TOutput | TExtended>;
    lastOrFail<TOutput>(predicateFn?: AsyncPredicate<TInput, IAsyncCollection<TInput>, TOutput>): LazyPromise<TOutput>;
    map<TOutput>(mapFn: AsyncMap<TInput, IAsyncCollection<TInput>, TOutput>): IAsyncCollection<TOutput>;
    max(): LazyPromise<Extract<TInput, number>>;
    median(): LazyPromise<Extract<TInput, number>>;
    min(): LazyPromise<Extract<TInput, number>>;
    nth(step: number): IAsyncCollection<TInput>;
    padEnd<TExtended>(maxLength: number, fillItems: AsyncIterableValue<TExtended>): IAsyncCollection<TInput | TExtended>;
    padStart<TExtended>(maxLength: number, fillItems: AsyncIterableValue<TExtended>): IAsyncCollection<TInput | TExtended>;
    page(page: number, pageSize: number): IAsyncCollection<TInput>;
    partition(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): IAsyncCollection<IAsyncCollection<TInput>>;
    percentage(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): LazyPromise<number>;
    pipe<TOutput>(callback: AsyncTransform<IAsyncCollection<TInput>, TOutput>): LazyPromise<TOutput>;
    prepend<TExtended>(iterable: AsyncIterableValue<TInput | TExtended>): IAsyncCollection<TInput | TExtended>;
    reduce(reduceFn: AsyncReduce<TInput, IAsyncCollection<TInput>, TInput>): LazyPromise<TInput>;
    reduce(reduceFn: AsyncReduce<TInput, IAsyncCollection<TInput>, TInput>, initialValue: TInput): LazyPromise<TInput>;
    reduce<TOutput>(reduceFn: AsyncReduce<TInput, IAsyncCollection<TInput>, TOutput>, initialValue: TOutput): LazyPromise<TOutput>;
    reject<TOutput>(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>, TOutput>): IAsyncCollection<Exclude<TInput, TOutput>>;
    repeat(amount: number): IAsyncCollection<TInput>;
    reverse(chunkSize?: number): IAsyncCollection<TInput>;
    searchFirst(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): LazyPromise<number>;
    searchLast(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): LazyPromise<number>;
    set(index: number, value: TInput | AsyncMap<TInput, IAsyncCollection<TInput>, TInput>): IAsyncCollection<TInput>;
    shuffle(mathRandom?: (() => number)): IAsyncCollection<TInput>;
    size(): LazyPromise<number>;
    skip(offset: number): IAsyncCollection<TInput>;
    skipUntil(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): IAsyncCollection<TInput>;
    skipWhile(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): IAsyncCollection<TInput>;
    slice(start?: number, end?: number): IAsyncCollection<TInput>;
    sliding(chunkSize: number, step?: number): IAsyncCollection<IAsyncCollection<TInput>>;
    sole<TOutput>(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>, TOutput>): LazyPromise<TOutput>;
    some<TOutput>(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>, TOutput>): LazyPromise<boolean>;
    sort(comparator?: Comparator<TInput>): IAsyncCollection<TInput>;
    split(chunkAmount: number): IAsyncCollection<IAsyncCollection<TInput>>;
    sum(): LazyPromise<Extract<TInput, number>>;
    take(limit: number): IAsyncCollection<TInput>;
    takeUntil(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): IAsyncCollection<TInput>;
    takeUntilAbort(abortSignal: AbortSignal, shouldThrow?: boolean): IAsyncCollection<TInput>;
    takeUntilTimeout(time: TimeSpan, shouldThrow?: boolean): IAsyncCollection<TInput>;
    takeWhile(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): IAsyncCollection<TInput>;
    tap(callback: AsyncTap<IAsyncCollection<TInput>>): IAsyncCollection<TInput>;
    toArray(): LazyPromise<TInput[]>;
    toIterator(): AsyncIterator<TInput, void, any>;
    toMap(): LazyPromise<EnsureMap<TInput>>;
    toRecord(): LazyPromise<EnsureRecord<TInput>>;
    unique<TOutput>(selectFn?: AsyncMap<TInput, IAsyncCollection<TInput>, TOutput>): IAsyncCollection<TInput>;
    values(): IAsyncCollection<TInput>;
    when<TExtended>(condition: boolean, callback: AsyncModifier<IAsyncCollection<TInput>, IAsyncCollection<TExtended>>): IAsyncCollection<TInput | TExtended>;
    whenEmpty<TExtended>(callback: AsyncModifier<IAsyncCollection<TInput>, IAsyncCollection<TExtended>>): IAsyncCollection<TInput | TExtended>;
    whenNot<TExtended>(condition: boolean, callback: AsyncModifier<IAsyncCollection<TInput>, IAsyncCollection<TExtended>>): IAsyncCollection<TInput | TExtended>;
    whenNotEmpty<TExtended>(callback: AsyncModifier<IAsyncCollection<TInput>, IAsyncCollection<TExtended>>): IAsyncCollection<TInput | TExtended>;
    zip<TExtended>(iterable: AsyncIterableValue<TExtended>): IAsyncCollection<[TInput, TExtended]>;
}

The IAsyncCollection contract offers a fluent and efficient approach to working with AsyncIterable objects. IAsyncCollection is immutable.

IMPORT_PATH: "@daiso-tech/core/collection/contracts"

Type Parameters

  • TInput = unknown

Type declaration

  • after:function
    • The after method returns the item that comes after the first item that matches predicateFn. If the collection is empty or the predicateFn does not match or matches the last item then null is returned.

      Parameters

      Returns LazyPromise<null | TInput>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .after(item => item === 2);
      // 3
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .after(item => item === 4);
      // null
      }
  • afterOr:function
    • The afterOr method returns the item that comes after the first item that matches predicateFn. If the collection is empty or the predicateFn does not match or matches the last item then defaultValue is returned.

      Type Parameters

      Parameters

      Returns LazyPromise<TInput | TExtended>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .afterOr(-1, item => item === 2);
      // 3
      }

      You can pass a function as default value.

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .afterOr(() => -1, item => item === 4);
      // -1
      }

      You can pass an async function as default value.

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .afterOr(async () => -1, item => item === 4);
      // -1
      }

      You can pass a LazyPromise as default value.

      import type { IAsyncCollection, ICache } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>, cache: ICache<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .afterOr(cache.get("a"), item => item > 10);
      // -1
      }
  • afterOrFail:function
    • The afterOrFail method returns the item that comes after the first item that matches predicateFn. If the collection is empty or the predicateFn does not match or matches the last item then an error is thrown.

      Parameters

      Returns LazyPromise<TInput>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .afterOrFail(item => item === 2);
      // 3
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .afterOrFail(item => item === 4);
      // error is thrown
      }
  • append:function
  • average:function
  • before:function
    • The before method returns the item that comes before the first item that matches predicateFn. If the predicateFn does not match or matches the first item then null is returned.

      Parameters

      Returns LazyPromise<null | TInput>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .before(item => item === 2);
      // 1
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .before(item => item === 1);
      // null
      }
  • beforeOr:function
    • The beforeOr method returns the item that comes before the first item that matches predicateFn. If the collection is empty or the predicateFn does not match or matches the first item then defaultValue is returned.

      Type Parameters

      Parameters

      Returns LazyPromise<TInput | TExtended>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .beforeOr(-1, item => item === 2);
      // 1
      }

      You can pass a function as default value.

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .beforeOr(() => -1, item => item === 1);
      // -1
      }

      You can pass an async function as default value.

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .beforeOr(async () => -1, item => item === 1);
      // -1
      }

      You can pass a LazyPromise as default value.

      import type { IAsyncCollection, ICache } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>, cache: ICache<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .beforeOr(cache.get("a"), item => item > 10);
      // -1
      }
  • beforeOrFail:function
    • The beforeOrFail method returns the item that comes before the first item that matches predicateFn. If the collection is empty or the predicateFn does not match or matches the first item then an error is thrown.

      Parameters

      Returns LazyPromise<TInput>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .beforeOrFail(item => item === 2);
      // 1
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .beforeOrFail(item => item === 1);
      // error is thrown
      }
  • change:function
  • chunk:function
    • The chunk method breaks the collection into multiple, smaller collections of size chunkSize. If chunkSize is not divisible with total number of items then the last chunk will contain the remaining items.

      Parameters

      • chunkSize: number

      Returns IAsyncCollection<IAsyncCollection<TInput>>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4, 5, 6, 7])
      .chunk(4)
      .map(chunk => chunk.toArray())
      .toArray();
      // [[1, 2, 3, 4], [5, 6, 7]]
      }
  • chunkWhile:function
  • collapse:function
  • count:function
  • countBy:function
    • The countBy method counts the occurrences of values in the collection by selectFn . By default the equality check occurs on the item.

      Type Parameters

      Parameters

      Returns IAsyncCollection<[TOutput, number]>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append(["a", "a", "a", "b", "b", "c"])
      .countBy()
      .map(([key, collection]) => [key, collection.toArray()])
      .toArray();
      // [
      // ["a", 3],
      // ["b", 2],
      // ["c", 1]
      // ]
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<string>): Promise<void> {
      await collection
      .append(["alice@gmail.com", "bob@yahoo.com", "carlos@gmail.com"])
      .countBy(item => item.split("@")[1])
      .toArray();
      // [
      // ["gmail.com", 2],
      // ["yahoo.com", 1]
      // ]
      }
  • crossJoin:function
    • The crossJoin method cross joins the collection's values among iterables, returning a Cartesian product with all possible permutations.

      Type Parameters

      • TExtended

      Parameters

      Returns IAsyncCollection<CrossJoinResult<TInput, TExtended>>

      import { ICollection } from "@daiso-tech/core";;

      async function(): Promise<void> {
      await collection
      .append([1, 2])
      .cross(["a", "b"])
      .toArray();
      // [
      // [1, "a"],
      // [1, "b"],
      // [2, "a"],
      // [2, "b"],
      // ]
      }
      import { ICollection } from "@daiso-tech/core";;

      async function(): Promise<void> {
      await collection
      .append([1, 2])
      .cross(["a", "b"])
      .cross(["I", "II"])
      .toArray();
      // [
      // [1, "a", "I"],
      // [1, "a", "II"],
      // [1, "b", "I"],
      // [1, "b", "II"],
      // [2, "a", "I"],
      // [2, "a", "II"],
      // [2, "b", "I"],
      // [2, "b", "II"],
      // ]
      }
  • delay:function
    • The delay method will add delay between each iteration. This method is especially useful for situations where you may be interacting with external APIs that rate limit incoming requests:

      Parameters

      Returns IAsyncCollection<TInput>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      class MyIterable implements Iterable<number> {
      async *[Symbol.asyncIterator]() {
      for (let i = 0; i < 10; i++) {
      yield i;
      }
      }
      }

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      const myIterable = new MyIterable();
      await collection
      .append(myIterable)
      .delay(1000)
      .forEach(user => console.log(user))
      }
  • difference:function
    • The difference method will return the values in the original collection that are not present in iterable. By default the equality check occurs on the item.

      Type Parameters

      Parameters

      Returns IAsyncCollection<TInput>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 2, 3, 4, 5])
      .difference([2, 4, 6, 8])
      .toArray();
      // [1, 3, 5]
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      type Phone = {
      name: string;
      brand: string;
      type: string;
      };

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<Phone>): Promise<void> {
      await collection
      .append([
      { 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" },
      ])
      .difference(
      [
      { name: "Apple Watch", brand: "Apple", type: "watch" },
      ],
      (product) => product.type
      )
      .toArray();
      // [
      // { name: "iPhone 6", brand: "Apple", type: "phone" },
      // { name: "iPhone 5", brand: "Apple", type: "phone" },
      // { name: "Galaxy S6", brand: "Samsung", type: "phone" },
      // ]
      }
  • entries:function
  • every:function
  • filter:function
  • first:function
    • The first method returns the first item in the collection that passes predicateFn . By default it will get the first item. If the collection is empty or no items passes predicateFn than null i returned.

      Type Parameters

      • TOutput

      Parameters

      Returns LazyPromise<null | TOutput>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .first();
      // 1
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .first(item => item > 2);
      // 3
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .first(item => item > 10);
      // null
      }
  • firstOr:function
    • The firstOr method returns the first item in the collection that passes predicateFn By default it will get the first item. If the collection is empty or no items passes predicateFn than defaultValue .

      Type Parameters

      Parameters

      Returns LazyPromise<TOutput | TExtended>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .firstOr(-1);
      // 1
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .firstOr(-1, item => item > 2);
      // 3
      }

      You can pass a function as default value.

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .firstOr(() => -1, item => item > 10);
      // -1
      }

      You can pass an async function as default value.

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .firstOr(async () => -1, item => item > 10);
      // -1
      }

      You can pass a LazyPromise as default value.

      import type { IAsyncCollection, ICache } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>, cache: ICache<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .firstOr(cache.get("a"), item => item > 10);
      // -1
      }
  • firstOrFail:function
    • The firstOrFail method returns the first item in the collection that passes predicateFn . By default it will get the first item. If the collection is empty or no items passes predicateFn than error is thrown.

      Type Parameters

      • TOutput

      Parameters

      Returns LazyPromise<TOutput>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .firstOrFail();
      // 1
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .firstOrFail(item => item > 2);
      // 3
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .firstOrFail(item => item > 10);
      // throws an error
      }
  • flatMap:function
    • The flatMap method returns a new array formed by applying mapFn to each item of the array, and then collapses the result by one level. It is identical to a map method followed by a collapse method.

      Type Parameters

      • TOutput

      Parameters

      Returns IAsyncCollection<TOutput>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<string[]>): Promise<void> {
      await collection
      .append([["a", "b"], ["c", "d"]])
      .flatMap(item => [item.length, ...item])
      .toArray();
      // [2, "a", "b", 2, "c", "d"]
      }
  • forEach:function
  • get:function
    • The get method returns the item by index. If the item is not found null will returned.

      Parameters

      • index: number

      Returns LazyPromise<null | TInput>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      collection = collection.append([1, 4, 2, 8, -2]);

      // Will be 2
      await collection.get(2);

      // Will be null
      await collection.get(5);
      }
  • getOrFail:function
    • The getOrFail method returns the item by index. If the item is not found an error will be thrown.

      Parameters

      • index: number

      Returns LazyPromise<TInput>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      collection = collection.append([1, 4, 2, 8, -2]);

      // Will be 2
      await collection.getOrFail(2);

      // An error will thrown
      await collection.getOrFail(5);
      }
  • groupBy:function
    • The groupBy method groups the collection's items by selectFn . By default the equality check occurs on the item.

      Type Parameters

      Parameters

      Returns IAsyncCollection<[TOutput, IAsyncCollection<TInput>]>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<string>): Promise<void> {
      await collection
      .append(["a", "a", "a", "b", "b", "c"])
      .groupBy()
      .map(([key, collection]) => [key, collection.toArray()])
      .toArray();
      // [
      // [
      // "a",
      // ["a", "a", "a"]
      // ],
      // [
      // "b",
      // ["b", "b"]
      // ],
      // [
      // "c",
      // ["c"]
      // ]
      // ]
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<string>): Promise<void> {
      await collection
      .append(["alice@gmail.com", "bob@yahoo.com", "carlos@gmail.com"])
      .groupBy(item => item.split("@")[1])
      .map(([key, collection]) => [key, collection.toArray()])
      .toArray();
      // [
      // [
      // "gmail.com",
      // ["alice@gmail.com", "carlos@gmail.com"]
      // ],
      // [
      // "yahoo.com",
      // ["bob@yahoo.com"]
      // ]
      // ]
      }
  • insertAfter:function
  • insertBefore:function
  • isEmpty:function
  • isNotEmpty:function
  • join:function
    • The join method joins the collection's items with separator . An error will be thrown when if a none string item is encounterd.

      Parameters

      • Optionalseparator: string

      Returns LazyPromise<Extract<TInput, string>>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .map(item => item.toString())
      .join();
      // "1,2,3,4"
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .map(item => item.toString())
      .join("_");
      // "1_2_3_4"
      }
  • keys:function
  • last:function
    • The last method returns the last item in the collection that passes predicateFn . By default it will get the last item. If the collection is empty or no items passes predicateFn than null i returned.

      Type Parameters

      • TOutput

      Parameters

      Returns LazyPromise<null | TOutput>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .last();
      // 4
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .last(item => item < 4);
      // 3
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .last(item => item > 10);
      // null
      }
  • lastOr:function
    • The lastOr method returns the last item in the collection that passes predicateFn . By default it will get the last item. If the collection is empty or no items passes predicateFn than defaultValue .

      Type Parameters

      Parameters

      Returns LazyPromise<TOutput | TExtended>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .lastOr(-1);
      // 4
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .lastOr(-1, item => item < 4);
      // 3
      }

      You can pass a function as default value.

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .lastOr(() => -1, item => item > 10);
      // -1
      }

      You can pass an async function as default value.

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .lastOr(async () => -1, item => item > 10);
      // -1
      }

      You can pass a LazyPromise as default value.

      import type { IAsyncCollection, ICache } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>, cache: ICache<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .lastOr(cache.get("a"), item => item > 10);
      // -1
      }
  • lastOrFail:function
    • The lastOrFail method returns the last item in the collection that passes predicateFn . By default it will get the last item. If the collection is empty or no items passes predicateFn than error is thrown.

      Type Parameters

      • TOutput

      Parameters

      Returns LazyPromise<TOutput>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .lastOrFail();
      // 4
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .lastOrFail(item => item < 4);
      // 3
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4])
      .lastOrFail(item => item > 10);
      // throws an error
      }
  • map:function
  • max:function
  • median:function
  • min:function
  • nth:function
  • padEnd:function
    • The padEnd method pads this collection with fillItems until the resulting collection size reaches maxLength. The padding is applied from the end of this collection.

      Type Parameters

      Parameters

      Returns IAsyncCollection<TInput | TExtended>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<string>): Promise<void> {
      await collection
      .append("abc")
      .padEnd(10, "foo")
      .join("");
      // "abcfoofoof"
      }
      async function main(collection: IAsyncCollection<string>): Promise<void> {
      await collection
      .append("abc")
      .padEnd(6, "123465")
      .join("");
      // "abc123"
      }
      async function main(collection: IAsyncCollection<string>): Promise<void> {
      await collection
      .append("abc")
      .padEnd(8, "0")
      .join("");
      // "abc00000"
      }
      async function main(collection: IAsyncCollection<string>): Promise<void> {
      await collection
      .append("abc")
      .padEnd(1, "_")
      .join("");
      // "abc"
      }
  • padStart:function
    • The padStart method pads this collection with fillItems until the resulting collection size reaches maxLength. The padding is applied from the start of this collection.

      Type Parameters

      Parameters

      Returns IAsyncCollection<TInput | TExtended>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<string>): Promise<void> {
      await collection
      .append("abc")
      .padStart(10, "foo")
      .join("");
      // "foofoofabc"
      }
      async function main(collection: IAsyncCollection<string>): Promise<void> {
      await collection
      .append("abc")
      .padStart(6, "123465")
      .join("");
      // "123abc"
      }
      async function main(collection: IAsyncCollection<string>): Promise<void> {
      await collection
      .append("abc")
      .padStart(8, "0")
      .join("");
      // "00000abc"
      }
      async function main(collection: IAsyncCollection<string>): Promise<void> {
      await collection
      .append("abc")
      .padStart(1, "_")
      .join("");
      // "abc"
      }
  • page:function
    • The page method returns a new collection containing the items that would be present on page with custom pageSize .

      Parameters

      • page: number
      • pageSize: number

      Returns IAsyncCollection<TInput>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4, 5, 6, 7, 8, 9])
      .page(2, 3)
      .toArray();
      // [4, 5, 6]
      }
  • partition:function
  • percentage:function
  • pipe:function
    • The pipe method passes the orignal collection to callback and returns the result from callback. This method is useful when you want compose multiple smaller functions.

      Type Parameters

      Returns LazyPromise<TOutput>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      function toNbrs<TInput>(
      collection: IAsyncCollection<TInput>,
      ): IAsyncCollection<number> {
      return collection
      .map((item) => Number(item))
      .reject((nbr) => Number.isNaN(nbr));
      }
      function nbrToStr(collection: IAsyncCollection<number>): number[] {
      return collection.repeat(2).toArray();
      }
      await collection
      .append([1, "2", "a", 1, 3, {}])
      .pipe(toNbrs)
      .then(nbrToStr);
      // [ 1, 2, 1, 3 ]
      }
  • prepend:function
  • reduce:function
  • reject:function
  • repeat:function
  • reverse:function
    • The reverse method will reverse the order of the collection. The reversing of the collection will be applied in chunks that are the size of chunkSize .

      Parameters

      • OptionalchunkSize: number

      Returns IAsyncCollection<TInput>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([-1, 2, 4, 3])
      .reverse()
      .toArray();
      // [3, 4, 2, -1]
      }
  • searchFirst:function
  • searchLast:function
  • set:function
    • The set method changes a item by i>index using value.

      Parameters

      Returns IAsyncCollection<TInput>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4, 5])
      .set(1, -1)
      .toArray();
      // [1, -1, 3, 4, 5]
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4, 5])
      .set(1, (prevValue) => prevValue - 2)
      .toArray();
      // [1, 0, 3, 4, 5]
      }
  • shuffle:function
  • size:function
  • skip:function
  • skipUntil:function
  • skipWhile:function
  • slice:function
    • The slice method creates porition of the original collection selected from start and end where start and end (end not included) represent the index of items in the collection.

      Parameters

      • Optionalstart: number
      • Optionalend: number

      Returns IAsyncCollection<TInput>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<string>): Promise<void> {
      await collection
      .append(["a", "b", "c", "d", "e", "f"])
      .slice(3)
      .toArray();
      // ["d", "e", "f"]
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<string>): Promise<void> {
      await collection
      .append(["a", "b", "c", "d", "e", "f"])
      .slice(undefined, 2)
      .toArray();
      // ["a", "b"]
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<string>): Promise<void> {
      await collection
      .append(["a", "b", "c", "d", "e", "f"])
      .slice(2, 5)
      .toArray();
      // ["c", "d", "e"]
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<string>): Promise<void> {
      await collection
      .append(["a", "b", "c", "d", "e", "f"])
      .slice(-2)
      .toArray();
      // ["e", "f"]
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<string>): Promise<void> {
      await collection
      .append(["a", "b", "c", "d", "e", "f"])
      .slice(undefined, -2)
      .toArray();
      // ["a", "b", "c", "d"]
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<string>): Promise<void> {
      await collection
      .append(["a", "b", "c", "d", "e", "f"])
      .slice(-4, -2)
      .toArray();
      // ["c", "d"]
      }
  • sliding:function
    • The sliding method returns a new collection of chunks representing a "sliding window" view of the items in the collection.

      Parameters

      • chunkSize: number
      • Optionalstep: number

      Returns IAsyncCollection<IAsyncCollection<TInput>>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4, 5])
      .sliding(2)
      .map(chunk => chunk.toArray())
      .toArray();
      // [[1, 2], [2, 3], [3, 4], [4, 5]]
      }
  • sole:function
    • The sole method returns the first item in the collection that passes predicateFn, but only if predicateFn matches exactly one item. If no items matches or multiple items are found an error will be thrown.

      Type Parameters

      • TOutput

      Returns LazyPromise<TOutput>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4, 5])
      .sole(item => item === 4);
      // 4
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4, 4, 5])
      .sole(item => item === 4);
      // error is thrown
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 5])
      .sole(item => item === 4);
      // error is thrown
      }
  • some:function
  • sort:function
    • The sort method sorts the collection. You can provide a comparator function.

      Parameters

      Returns IAsyncCollection<TInput>

      import type { IAsyncCollection } from "@daiso-tech/core";

      type Person = {
      name: string;
      age: number;
      };

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<Person>): Promise<void> {
      await collection
      .append([-1, 2, 4, 3])
      .sort()
      .toArray();
      // [-1, 2, 3, 4]
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([
      { name: "Anders", age: 30 },
      { name: "Joe", age: 20 },
      { name: "Hasan", age: 25 },
      { name: "Linda", age: 19 }
      ])
      .sort(({ age: ageA }, { age: ageB }) => ageA - ageB)
      .toArray();
      // [
      // { name: "Linda", age: 19 }
      // { name: "Joe", age: 20 },
      // { name: "Hasan", age: 25 },
      // { name: "Anders", age: 30 },
      // ]
      }
  • split:function
    • The split method breaks a collection evenly into chunkAmount of chunks.

      Parameters

      • chunkAmount: number

      Returns IAsyncCollection<IAsyncCollection<TInput>>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4, 5])
      .split(3)
      .map(chunk => chunk.toArray())
      .toArray();
      // [[1, 2], [3, 4], [5]]
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4, 5, 6])
      .split(3)
      .map(chunk => chunk.toArray())
      .toArray();
      // [[1, 2], [3, 4], [5, 6]]
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4, 5, 6, 7])
      .split(3)
      .map(chunk => chunk.toArray())
      .toArray();
      // [[1, 2, 7], [3, 4], [5, 6]]
  • sum:function
  • take:function
    • The take method takes the first limit items.

      Parameters

      • limit: number

      Returns IAsyncCollection<TInput>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([0, 1, 2, 3, 4, 5])
      .take(3)
      .toArray();
      // [0, 1, 2]
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([0, 1, 2, 3, 4, 5])
      .take(-2)
      .toArray();
      // [0, 1, 2, 3]
      }
  • takeUntil:function
  • takeUntilAbort:function
    • Experimental

      The takeUntilAbort method returns a new collection that will iterate values until aborted by passing in AbortSignal. After when aborted, the collection will stop iterating:

      Parameters

      • abortSignal: AbortSignal
      • OptionalshouldThrow: boolean

      Returns IAsyncCollection<TInput>

      import type { IAsyncCollection } from "@daiso-tech/core";

      class InfiniteIterable implements Iterable<number> {
      async *[Symbol.asyncIterator]() {
      let index = 0;
      while(true) {
      index++;
      yield index;
      }
      }
      }

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      const abortController = new AbortController();
      setTimeout(() => {
      abortController.abort("My abort error");
      }, 1000)
      const infiniteIterable = new InfiniteIterable();
      await collection
      .append(infiniteIterable);
      .takeUntilAbort(abortController)
      .forEach(nbr => console.log(nbr))
      }
  • takeUntilTimeout:function
    • Experimental

      The takeUntilTimeout method returns a new collection that will iterate values until the specified time. After that time, the collection will stop iterating:

      Parameters

      • time: TimeSpan
      • OptionalshouldThrow: boolean

      Returns IAsyncCollection<TInput>

      import type { IAsyncCollection } from "@daiso-tech/core";

      class InfiniteIterable implements AsyncIterable<number> {
      async *[Symbol.asyncIterator]() {
      let index = 0;
      while(true) {
      index++;
      yield index;
      }
      }
      }

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      const infiniteIterable = new InfiniteIterable();
      await collection
      .append(infiniteIterable)
      .takeUntilTimeout(1000)
      .forEach(nbr => console.log(nbr))
      }
  • takeWhile:function
  • tap:function
    • The tap method passes a copy of the original collection to callback, allowing you to do something with the items while not affecting the original collection.

      Parameters

      Returns IAsyncCollection<TInput>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([1, 2, 3, 4, 5, 6])
      .tap(collection => {
      collection
      .filter(value => value % 2 === 0)
      .forEach(value => console.log(value))
      })
      .toArray();
      // [1, 2, 3, 4, 5, 6]
      }
  • toArray:function
  • toIterator:function
  • toMap:function
  • toRecord:function
  • unique:function
    • The unique method removes all duplicate values from the collection by selectFn . By default the equality check occurs on the item.

      Type Parameters

      Parameters

      Returns IAsyncCollection<TInput>

      import type { IAsyncCollection } from "@daiso-tech/core";

      type Phone = {
      name: string;
      brand: string;
      type: string;
      };

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<Phone>): Promise<void> {
      await collection
      .append([1, 1, 2, 2, 3, 4, 2])
      .unique()
      .toArray();
      // [1, 2, 3, 4]
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<number>): Promise<void> {
      await collection
      .append([
      { 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" },
      ])
      .unique(item => item.brand)
      .toArray();
      // [
      // { name: "iPhone 6", brand: "Apple", type: "phone" },
      // { name: "Galaxy S6", brand: "Samsung", type: "phone" },
      // ]
      }
  • values:function
  • when:function
  • whenEmpty:function
  • whenNot:function
  • whenNotEmpty:function
  • zip:function
    • The zip method merges together the values of iterable with the values of the collection at their corresponding index. The returned collection has size of the shortest collection.

      Type Parameters

      • TExtended

      Parameters

      Returns IAsyncCollection<[TInput, TExtended]>

      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<string>): Promise<void> {
      await collection
      .append(["Chair", "Desk"])
      .zip([100, 200])
      .toArray();
      // [["Chair", 100], ["Desk", 200]]
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<string>): Promise<void> {
      await collection
      .append(["Chair", "Desk", "Couch"])
      .zip([100, 200])
      .toArray();
      // [["Chair", 100], ["Desk", 200]]
      }
      import type { IAsyncCollection } from "@daiso-tech/core";

      // Asume the inputed collection is empty.
      async function main(collection: IAsyncCollection<string>): Promise<void> {
      await collection
      .append(["Chair", "Desk"])
      .zip([100, 200, 300])
      .toArray();
      // [["Chair", 100], ["Desk", 200]]
      }