Skip to main content

concat

concat() function

Returns the result of concatenating the given iterable.

Signature:
declare function concat<A extends Iterable<unknown> | AsyncIterable<unknown>, B extends Iterable<unknown> | AsyncIterable<unknown>>(iterable1: A, iterable2: B): ReturnConcatType<A, B>;

declare function concat<A extends Iterable<unknown> | AsyncIterable<unknown>, B extends Iterable<unknown> | AsyncIterable<unknown>>(iterable1: A): (iterable2: B) => ReturnConcatType<A, B>;

Example

const iter = concat([1, 2], [3, 4]);
iter.next() // {done:false, value: 1}
iter.next() // {done:false, value: 2}
iter.next() // {done:false, value: 3}
iter.next() // {done:false, value: 4}
iter.next() // {done:true, value: undefined}

// with pipe
pipe(
[3, 4],
concat([1, 2]),
toArray,
); // [1, 2, 3, 4]

await pipe(
Promise.resolve([3, 4]),
concat([1, 2]),
toArray,
); // [1, 2, 3, 4]

await pipe(
[Promise.resolve(3), Promise.resolve(4)],
toAsync,
concat([1, 2]),
toArray,
); // [1, 2, 3, 4]

Try It

see pipe, toAsync, toArray