import { extremaBy } from './_extremaby' ; import { ExtremaOptions } from './extremaoptions' ; import { equalityComparerAsync } from '../util/comparer' ; template TSource template TKey param { AsyncIterable < TSource > } source param { ExtremaOptions < TSource , TKey > } options returns { Promise < TSource [ ] > } export function minBy < TSource , TKey > ( source , options ? ) { const { [ 'comparer' ] : comparer = equalityComparerAsync , [ 'selector' ] : selector , [ 'signal' ] : signal , } = options || { } ; const newComparer = async ( key , minValue ) => - ( await comparer ( key , minValue ) ) ; return extremaBy ( source , selector ! , newComparer , signal ) ; }