Skip to main content
Module

x/rimbu/mod.ts>AsyncReducer.maxBy

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
variable AsyncReducer.maxBy
import { AsyncReducer } from "https://deno.land/x/rimbu@0.14.0/mod.ts";
const { maxBy } = AsyncReducer;

Returns a Reducer that remembers the maximum value of the inputs using the given compFun to compare input values

Examples

Example 1

const stream = Stream.of('abc', 'a', 'abcde', 'ab')
console.log(stream.maxBy((s1, s2) => s1.length - s2.length))
// 'abcde'

type

{ <T>(compFun: (v1: T, v2: T) => MaybePromise<number>): AsyncReducer<T, T | undefined>; <T, O>(compFun: (v1: T, v2: T) => MaybePromise<number>, otherwise: AsyncOptLazy<O>): AsyncReducer<T, T | O>; }