@codibre/fluent-iterable
Version:
Provides LINQ-like fluent api operations for iterables and async iterables (ES2018+).
16 lines (15 loc) • 692 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.topRecipe = topRecipe;
const prepare_1 = require("../types-internal/prepare");
function topRecipe({ reduceAndMap, resolver }) {
return function (baseMapper, comparer) {
const mapper = (0, prepare_1.prepare)(baseMapper);
return reduceAndMap.call(this, (current, next) => {
return resolver(mapper(next), (value) => !current.found ||
(current.value && comparer(value, current.value) > 0)
? { value, item: next, found: true }
: current);
}, { value: undefined, item: undefined, found: false }, (acc) => acc.item);
};
}