Produces a one-value iterable, with the last emitted value.
import {pipe, last} from 'iter-ops';const i = pipe( [1, 2, 3], last());console.log(...i); //=> 3console.log(i.first); //=> 3 Copy
import {pipe, last} from 'iter-ops';const i = pipe( [1, 2, 3], last());console.log(...i); //=> 3console.log(i.first); //=> 3
When the optional predicate is provided, the last value satisfying it will be emitted.
import {pipe, last} from 'iter-ops';const i = pipe( [1, 2, 3, 4, 5, 6, 7, 8, 9], last(a => a % 2 === 0) // last even number);console.log(i.first); //=> 8 Copy
import {pipe, last} from 'iter-ops';const i = pipe( [1, 2, 3, 4, 5, 6, 7, 8, 9], last(a => a % 2 === 0) // last even number);console.log(i.first); //=> 8
Note that the predicate can only return a Promise inside an asynchronous pipeline, or else the Promise will be treated as a truthy value.
Promise
Optional
Produces a one-value iterable, with the last emitted value.
When the optional predicate is provided, the last value satisfying it will be emitted.
Note that the predicate can only return a
Promise
inside an asynchronous pipeline, or else thePromise
will be treated as a truthy value.