Function zipLongest

  • Returns a Stream that merges elements from both iterables by taking one element from each, passing them to the function, and yielding the result.

    Type Parameters

    • A
    • B
    • F
    • O

    Parameters

    • a: Iterable<A>

      The first iterable to merge.

    • b: Iterable<B>

      The second iterable to merge.

    • fillValue: ValueOrFactory<F>

      The value or factory to use when one iterable is done.

    • zipFunction: ((a: A | F, b: B | F) => O)

      The function that merges the elements.

        • (a, b): O
        • Parameters

          Returns O

    Returns Stream<O>

    A Stream that merges elements from both iterables.

    const result = zipLongest('ABCD', 'xy', ' ', (a, b) => `${a}${b}`);
    console.log([...result]); // ['Ax', 'By', 'C ', 'D ']