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

    Function zipMany

    • Zips source with the iterables supplied in iterables, producing aligned tuples.

      Type Parameters

      • TElement

        Type of elements in the source iterable.

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

        Extends readonly Iterable<unknown>[]; each iterable's element type contributes to the resulting tuple.

      Parameters

      • source: Iterable<TElement>

        The primary iterable zipped with the additional iterables.

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

        Additional iterables to zip with source.

      Returns IEnumerable<[TElement, ...UnpackIterableTuple<TIterable>[]]>

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

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

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

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

      Type Parameters

      • TElement

        Type of elements in the source iterable.

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

        Extends readonly Iterable<unknown>[]; each iterable's element type contributes to the zipper input tuple.

      • TResult

        Result type produced by ZipManyZipper zipper.

      Parameters

      • source: Iterable<TElement>

        The primary iterable zipped with the additional iterables.

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

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

      Returns IEnumerable<TResult>

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

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

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

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