last
last() function
Returns the last element of Iterable/AsyncIterable
Signature:declare function last<T extends Iterable<unknown> | AsyncIterable<unknown>>(iterable: T): LastReturnType<T>;
Example
last([1, 2, 3, 4, 5]); // 5
// with pipe
pipe(
[1, 2, 3, 4, 5],
last,
); // 5
await pipe(
Promise.resolve([1, 2, 3, 4, 5]),
last,
); // 5
// with toAsync
await pipe(
[Promise.resolve(1), Promise.resolve(2), Promise.resolve(3)],
toAsync,
last,
); // 3