Skip to main content

append

append() function

Returns Iterable/AsyncIterable containing the contents of the given iterable, followed by the given element.

Signature:
declare function append<A>(a: A, iterable: Iterable<A>): IterableIterator<A>;

declare function append<A>(a: A | Promise<A>, iterable: AsyncIterable<A>): AsyncIterableIterator<A>;

declare function append<A, B extends Iterable<A> | AsyncIterable<Awaited<A>>>(a: A): (iterable: B) => ReturnIterableIteratorType<B, Awaited<A>>;

Example

const iter = append(4, [1,2,3]);
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(
[1,2,3],
append(4),
toArray,
); // [1,2,3,4]

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

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

Try It

see pipe, toAsync, toArray

Open Source Code