Skip to main content

takeRight

takeRight() function

Returns Iterable/AsyncIterable that taken the last argument l values from iterable

Signature:
declare function takeRight<A>(l: number, iterable: Iterable<A>): IterableIterator<A>;

declare function takeRight<A>(l: number, iterable: AsyncIterable<A>): AsyncIterableIterator<A>;

declare function takeRight<A extends Iterable<unknown> | AsyncIterable<unknown>>(l: number): (iterable: A) => ReturnIterableIteratorType<A>;

Example

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

// with pipe
pipe(
[0, 1, 2, 3, 4, 5, 6],
takeRight(2),
toArray,
); // [5, 6]

await pipe(
Promise.resolve([0, 1, 2, 3, 4, 5, 6]),
takeRight(2),
toArray,
); // [5, 6]

// with toAsync
await pipe(
[Promise.resolve(0), Promise.resolve(1), Promise.resolve(2),
Promise.resolve(3), Promise.resolve(4), Promise.resolve(5), Promise.resolve(6)],
toAsync,
takeRight(2),
toArray,
); // [5, 6]

see pipe, toAsync, toArray