axax
Version:
A library of async iterator extensions for JavaScript including ```map```, ```reduce```, ```filter```, ```flatMap```, ```pipe``` and [more](https://github.com/jamiemccrindle/axax/blob/master/docs/API.md#functions).
20 lines (19 loc) • 528 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Take the last value or the last value to pass predicate from an async iterable
*/
function last(predicate = () => true, defaultValue) {
return async function* inner(source) {
let lastItem = defaultValue;
for await (const item of source) {
if (predicate(item)) {
lastItem = item;
}
}
if (lastItem) {
yield lastItem;
}
};
}
exports.last = last;