ix
Version:
The Interactive Extensions for JavaScript
24 lines (22 loc) • 1.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.minBy = void 0;
const tslib_1 = require("tslib");
const _extremaby_js_1 = require("./_extremaby.js");
const comparer_js_1 = require("../util/comparer.js");
/**
* Returns the elements in an async-enumerable sequence with the minimum key value.
*
* @template TSource The type of the elements in the source sequence.
* @template TKey The type of the key computed for each element in the source sequence.
* @param {AsyncIterable<TSource>} source An async-iterable sequence to get the minimum elements for.
* @param {ExtremaOptions<TSource, TKey>} options The options which include an optional comparer and abort signal.
* @returns {Promise<TSource[]>} A promise containing a list of zero or more elements that have a minimum key value.
*/
function minBy(source, options) {
const { ['comparer']: comparer = comparer_js_1.equalityComparerAsync, ['selector']: selector, ['signal']: signal, } = options || {};
const newComparer = (key, minValue) => tslib_1.__awaiter(this, void 0, void 0, function* () { return -(yield comparer(key, minValue)); });
return (0, _extremaby_js_1.extremaBy)(source, selector, newComparer, signal);
}
exports.minBy = minBy;
//# sourceMappingURL=minby.js.map