Type Alias ICollection<TInput>

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

The ICollection contract offers a fluent and efficient approach to working with Iterable objects. ICollection 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 null | TInput

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

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([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 TInput | TExtended

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([1, 2, 3, 4])
      .afterOr(-1, item => item === 2);
      // 3
      }
      import type { ICollection } from "@daiso-tech/core";

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([1, 2, 3, 4])
      .afterOr(-1, item => item === 4);
      // -1
      }
      import type { ICollection } from "@daiso-tech/core";

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([1, 2, 3, 4])
      .afterOr(() => -1, item => item === 4);
      // -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 TInput

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

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([1, 2, 3, 4])
      .afterOrFail(item => item === 4);
      // error is thrown
      }
  • append:function
  • average:function
    • The average method returns the average of all items in the collection. If the collection includes other than number items an error will be thrown. If the collection is empty an error will also be thrown.

      Returns Extract<TInput, number>

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .append([1, 2, 3])
      .average()
      // 2
      }
  • 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 null | TInput

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

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([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 TInput | TExtended

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([1, 2, 3, 4])
      .beforeOr(-1, item => item === 2);
      // 1
      }
      import type { ICollection } from "@daiso-tech/core";

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([1, 2, 3, 4])
      .beforeOr(-1, item => item === 1);
      // -1
      }
      import type { ICollection } from "@daiso-tech/core";

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([1, 2, 3, 4])
      .beforeOr(() => -1, item => item === 1);
      // -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 TInput

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

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([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 ICollection<ICollection<TInput>>

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection.apppend([1, 2, 3, 4, 5, 6, 7]);
      const chunks = collection.chunk(4);
      chunks.map(chunk => chunk.toArray()).toArray();
      // [[1, 2, 3, 4], [5, 6, 7]]
      }
  • chunkWhile:function
    • The chunkWhile method breaks the collection into multiple, smaller collections based on the evaluation of predicateFn. The chunk variable passed to the predicateFn may be used to inspect the previous item.

      Parameters

      Returns ICollection<ICollection<TInput>>

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<string>): void {
      collection
      .apppend("AABBCCCD")
      .chunkWhile((value, index, chunk) => {
      return value === chunk.last();
      })
      .map(chunk => chunk.toArray())
      .toArray();
      // [["A", "A"], ["B", "B"], ["C", "C", "C"], ["D"]]
      }
  • collapse:function
  • count:function
    • The count method returns the total number of items in the collection that passes predicateFn.

      Parameters

      Returns number

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([1, 2, 3, 4, 5, 6])
      .count(value => value % 2 === 0);
      // 3
      }
  • 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 ICollection<[TOutput, number]>

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<string>): void {
      collection
      .apppend(["a", "a", "a", "b", "b", "c"])
      .countBy()
      .map(([key, collection]) => [key, .toArray()])
      .toArray();
      // [
      // ["a", 3],
      // ["b", 2],
      // ["c", 1]
      // ]
      }
      import type { ICollection } from "@daiso-tech/core";

      // Assume the inputed collection is empty.
      function main(collection: ICollection<string>): void {
      collection
      .apppend(["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 ICollection<CrossJoinResult<TInput, TExtended>>

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([1, 2])
      .cross(["a", "b"])
      .toArray();
      // [
      // [1, "a"],
      // [1, "b"],
      // [2, "a"],
      // [2, "b"],
      // ]
      }
      import type { ICollection } from "@daiso-tech/core";

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([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"],
      // ]
      }
  • 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 ICollection<TInput>

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

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

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<Phone>): void {
      collection
      .apppend([
      { 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
    • The every method determines whether all items in the collection matches predicateFn.

      Type Parameters

      • TOutput

      Parameters

      Returns boolean

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .append([0, 1, 2, 3, 4, 5])
      .every(item => item < 6);
      // true
      }
  • 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 null | TOutput

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

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

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([1, 2, 3, 4])
      .first(item => item > 10);
      // null
      }

      // 3

  • 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 TOutput | TExtended

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

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([1, 2, 3, 4])
      .firstOr(-1, item => item > 2);
      // 3
      }
      import type { ICollection } from "@daiso-tech/core";

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([1, 2, 3, 4])
      .firstOr(-1, item => item > 10);
      // -1
      }
      import type { ICollection } from "@daiso-tech/core";

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([1, 2, 3, 4])
      .firstOr(() => -1, 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 TOutput

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

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

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([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 ICollection<TOutput>

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<string[]>): void {
      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 null | TInput

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

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

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

      // Will be null
      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 TInput

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

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

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

      // An error will thrown
      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 ICollection<[TOutput, ICollection<TInput>]>

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

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<string>): void {
      collection.apppend(["alice@gmail.com", "bob@yahoo.com", "carlos@gmail.com"]);
      const group = collection
      .groupBy(item => item.split("@")[1])
      .map(([key, collection]) => [key, .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 Extract<TInput, string>

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

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      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 null | TOutput

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

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

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([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 TOutput | TExtended

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

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([1, 2, 3, 4])
      .lastOr(-1, item => item < 4);
      // 3
      }
      import type { ICollection } from "@daiso-tech/core";

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([1, 2, 3, 4])
      .lastOr(-1, item => item > 10);
      // -1
      }
      import type { ICollection } from "@daiso-tech/core";

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([1, 2, 3, 4])
      .lastOr(() => -1, 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 TOutput

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

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

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .lastOrFail(item => item > 10);
      .apppend([1, 2, 3, 4])
      // throws an error
      }
  • map:function
    • The map method iterates through the collection and passes each item to mapFn. The mapFn is free to modify the item and return it, thus forming a new collection of modified items.

      Type Parameters

      • TOutput

      Parameters

      Returns ICollection<TOutput>

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .append([1, 2, 3, 4, 5])
      .map(item => item * 2)
      .toArray();
      // [2, 4, 6, 8, 10]
      }
  • max:function
    • The max method returns the max of all items in the collection. If the collection includes other than number items an error will be thrown. If the collection is empty an error will also be thrown.

      Returns Extract<TInput, number>

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .append([1, 2, 3])
      .max();
      // 3
      }
  • median:function
    • The median method returns the median of all items in the collection. If the collection includes other than number items an error will be thrown. If the collection is empty an error will also be thrown.

      Returns Extract<TInput, number>

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .append([1, 2, 3])
      .median();
      // 2
      }
  • min:function
    • The min method returns the min of all items in the collection. If the collection includes other than number items an error will be thrown. If the collection is empty an error will also be thrown.

      Returns Extract<TInput, number>

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .append([1, 2, 3])
      .min();
      // 1
      }
  • nth:function
    • The nth method creates a new collection consisting of every n-th item.

      Parameters

      • step: number

      Returns ICollection<TInput>

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<string>): void {
      collection
      .apppend(["a", "b", "c", "d", "e", "f"])
      .nth(4)
      .toArray();
      // ["a", "e"]
      }
  • 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

      • maxLength: number
      • fillItems: Iterable<TExtended, any, any>

      Returns ICollection<TInput | TExtended>

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<string>): void {
      collection
      .append("abc")
      .padEnd(10, "foo")
      .join("");
      // "abcfoofoof"
      }
      import type { ICollection } from "@daiso-tech/core";

      // Assume the inputed collection is empty.
      function main(collection: ICollection<string>): void {
      collection
      .append("abc")
      .padEnd(6, "123465")
      .join("");
      // "abc123"
      }
      import type { ICollection } from "@daiso-tech/core";

      // Assume the inputed collection is empty.
      function main(collection: ICollection<string>): void {
      collection
      .append("abc")
      .padEnd(8, "0")
      .join("");
      // "abc00000"

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<string>): void {
      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

      • maxLength: number
      • fillItems: Iterable<TExtended, any, any>

      Returns ICollection<TInput | TExtended>

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<string>): void {
      collection
      .append("abc")
      .padStart(10, "foo")
      .join("");
      // "foofoofabc"
      }
      function main(collection: ICollection<string>): void {
      collection
      .append("abc")
      .padStart(6, "123465")
      .join("");
      // "123abc"
      }
      function main(collection: ICollection<string>): void {
      collection
      .append("abc")
      .padStart(8, "0")
      .join("");
      // "00000abc"
      }
      function main(collection: ICollection<string>): void {
      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 ICollection<TInput>

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .append([1, 2, 3, 4, 5, 6, 7, 8, 9])
      .page(2, 3)
      .toArray()
      // [4, 5, 6]
      }
  • partition:function
  • percentage:function
    • The percentage method may be used to quickly determine the percentage of items in the collection that pass predicateFn. If the collection is empty an error will also be thrown.

      Parameters

      Returns number

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .append([1, 1, 2, 2, 2, 3])
      .percentage(value => value === 1);
      // 33.333
      }
  • 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

      Parameters

      Returns TOutput

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      function toNbrs<TInput>(
      collection: ICollection<TInput>,
      ): ICollection<number> {
      return collection
      .map((item) => Number(item))
      .reject((nbr) => Number.isNaN(nbr));
      }

      function nbrToStr(collection: ICollection<number>): number[] {
      return collection.repeat(2).toArray();
      }

      const piped = collection
      .apppend([1, "2", "a", 1, 3, {}])
      .pipe(toNbrs)
      .pipe(nbrToStr);
      // [ 1, 2, 1, 3 ]
      }
  • prepend:function
  • reduce:function
  • reject:function
  • repeat:function
    • The repeat method will repeat the original collection amount times.

      Parameters

      • amount: number

      Returns ICollection<TInput>

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([1, 2, 3])
      .repeat(3)
      .toArray();
      // [1, 2, 3, 1, 2, 3, 1, 2, 3]
      }
  • 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 ICollection<TInput>

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([-1, 2, 4, 3])
      .reverse()
      .toArray();
      // [3, 4, 2, -1]
      }
  • searchFirst:function
    • The searchFirst return the index of the first item that matches predicateFn.

      Parameters

      Returns number

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<string>): void {
      collection
      .apppend(["a", "b", "b", "c"])
      .searchFirst(item => item === "b");
      // 1
      }
  • searchLast:function
    • The searchLast return the index of the last item that matches predicateFn.

      Parameters

      Returns number

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<string>): void {
      collection
      .apppend(["a", "b", "b", "c"])
      .searchLast(item => item === "b");
      // 2
      }
  • set:function
    • The set method changes a item by i>index using value.

      Parameters

      Returns ICollection<TInput>

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

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .append([1, 2, 3, 4, 5])
      .set(1, (prevValue) => prevValue - 2)
      .toArray();
      // [1, 0, 3, 4, 5]
      }
  • shuffle:function
  • size:function
  • skip:function
    • The skip method skips the first offset items.

      Parameters

      • offset: number

      Returns ICollection<TInput>

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .append([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
      .skip(4)
      .toArray();
      // [5, 6, 7, 8, 9, 10]
      }
  • 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 ICollection<TInput>

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

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

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

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

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

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<string>): void {
      collection
      .apppend(["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 ICollection<ICollection<TInput>>

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([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

      Parameters

      Returns TOutput

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

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

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([1, 2, 3, 5])
      .sole(item => item === 4);
      // error is thrown
      }
  • some:function
    • The some method determines whether at least one item in the collection matches predicateFn.

      Type Parameters

      • TOutput

      Parameters

      Returns boolean

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .append([0, 1, 2, 3, 4, 5])
      .some(item => item === 1);
      // true
      }
  • sort:function
    • The sort method sorts the collection. You can provide a comparator function.

      Parameters

      Returns ICollection<TInput>

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([-1, 2, 4, 3])
      .sort()
      .toArray()
      // [-1, 2, 3, 4]
      }
      import type { ICollection } from "@daiso-tech/core";

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<Person>): void {
      collection
      .apppend([
      { 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 ICollection<ICollection<TInput>>

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

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

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([1, 2, 3, 4, 5, 6, 7])
      .split(3)
      .map(chunk => chunk.toArray())
      .toArray();
      // [[1, 2, 7], [3, 4], [5, 6]]
      }
  • sum:function
    • The sum method returns the sum of all items in the collection. If the collection includes other than number items an error will be thrown. If the collection is empty an error will also be thrown.

      Returns Extract<TInput, number>

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .append([1, 2, 3])
      .sum();
      // 6
      }
  • take:function
    • The take method takes the first limit items.

      Parameters

      • limit: number

      Returns ICollection<TInput>

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

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .append([0, 1, 2, 3, 4, 5])
      .take(-2)
      .toArray();
      // [0, 1, 2, 3]
      }
  • takeUntil:function
  • 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 ICollection<TInput>

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection.apppend([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 ICollection<TInput>

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([1, 1, 2, 2, 3, 4, 2])
      .unique()
      .toArray();
      // [1, 2, 3, 4]
      }
      import type { ICollection } from "@daiso-tech/core";

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<Phone>): void {
      collection
      .apppend([
      { 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
    • The whenEmpty method will execute callback when the collection is empty.

      Type Parameters

      Returns ICollection<TInput | TExtended>

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([])
      .whenEmpty(collection => collection.append([-3]))
      .toArray();
      // [-3]
      }
      import type { ICollection } from "@daiso-tech/core";

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection
      .apppend([1])
      .whenEmpty(collection => collection.append([-3]))
      .toArray();
      // [1]
      }
  • whenNot:function
  • whenNotEmpty:function
    • The whenNotEmpty method will execute callback when the collection is not empty.

      Type Parameters

      Returns ICollection<TInput | TExtended>

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection.apppend([])
      .whenNotEmpty(collection => collection.append([-3]))
      .toArray();
      // []
      }
      import type { ICollection } from "@daiso-tech/core";

      // Assume the inputed collection is empty.
      function main(collection: ICollection<number>): void {
      collection = collection
      .apppend([1])
      .whenNotEmpty(collection => collection.append([-3]))
      .toArray();
      // [1, -3]
      }
  • 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 ICollection<[TInput, TExtended]>

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

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

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

      // Assume the inputed collection is empty.
      function main(collection: ICollection<string>): void {
      collection
      .apppend(["Chair", "Desk"])
      .zip([100, 200, 300])
      .toArray();
      // [["Chair", 100], ["Desk", 200]]
      }