Skip to content

prepend() function

Returns Iterable/AsyncIterable with the given element at the front, followed by the contents of iterable.

Signature:

typescript
declare function prepend<A>(a: A, iterable: Iterable<A>): IterableIterator<A>;

Example

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

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

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

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

Try It

see pipe, toAsync, toArray

Open Source Code

Released under the Apache-2.0 License.