Skip to main content

Function: toMaxWith()

toMaxWith<Value>(fn): OptionalReducer<Value>

Returns an optional reducer that finds the maximum value of the values it receives by comparing the numerical values of each value, as defined by fn.

Use when composing reducers. Prefer maxWith for direct use on iterables.

Type Parameters

Value

Parameters

fn

Returns

OptionalReducer<Value>

Example

console.log(
pipe(
[`sloth`, `more sloth`, `sleep`, `some sloth`],
map(string => [string.length, string]),
reduce(toGrouped(toMaxWith(string => string.codePointAt(0)), toMap())),
),
)
//=> Map(2) { 5 => 'sloth', 10 => 'some sloth' }

Defined in

statistics.d.ts:788