UNPKG

958 BJavaScriptView Raw
1import { extremaBy } from './_extremaby';
2import { equalityComparerAsync } from '../util/comparer';
3/**
4 * Returns the elements in an async-iterable sequence with the maximum 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 maximum 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 maximum key value.
12 */
13export function maxBy(source, options) {
14 const { ['comparer']: comparer = equalityComparerAsync, ['selector']: selector, ['signal']: signal, } = options || {};
15 return extremaBy(source, selector, comparer, signal);
16}
17
18//# sourceMappingURL=maxby.mjs.map