Skip to content

last() function

Returns the last element of Iterable/AsyncIterable

Signature:

typescript
declare function last<T extends Iterable<unknown> | AsyncIterable<unknown>>(iterable: T): LastReturnType<T>;

Example

ts
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

Try It

see pipe, toAsync

Open Source Code

Released under the Apache-2.0 License.