Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/rimbu/core/mod.ts>Reducer.maxBy

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

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) => number): Reducer<T, T | undefined>; <T, O>(compFun: (v1: T, v2: T) => number, otherwise: OptLazy<O>): Reducer<T, T | O>; }