UNPKG

1.04 kBJavaScriptView Raw
1import { extremaBy } from './_extremaby';
2import { equalityComparerAsync } from '../util/comparer';
3/**
4 * Returns the elements in an async-enumerable sequence with the minimum key value.
5 *
6 * @export
7 * @template TSource The type of the elements in the source sequence.
8 * @template TKey The type of the key computed for each element in the source sequence.
9 * @param {AsyncIterable<TSource>} source An async-iterable sequence to get the minimum elements for.
10 * @param {ExtremaOptions<TSource, TKey>} options The options which include an optional comparer and abort signal.
11 * @returns {Promise<TSource[]>} A promise containing a list of zero or more elements that have a minimum key value.
12 */
13export function minBy(source, options) {
14 const { ['comparer']: comparer = equalityComparerAsync, ['selector']: selector, ['signal']: signal, } = options || {};
15 const newComparer = async (key, minValue) => -(await comparer(key, minValue));
16 return extremaBy(source, selector, newComparer, signal);
17}
18
19//# sourceMappingURL=minby.mjs.map