UNPKG

fast-iterable

Version:

Provides LINQ-like fluent api operations for iterables and async iterables (ES2018+).

17 lines (16 loc) 720 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.topRecipe = void 0; 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); }; } exports.topRecipe = topRecipe;