For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/fp/maxBy.md.

maxBy (Functional Programming) es-toolkit

Creates a function that returns the value with the largest computed score. Use it with pipe.

const result = pipe(array, maxBy(getValue));
Info

Prefer the original es-toolkit maxBy in ordinary code. Use this fp variant when composing transformations with pipe.

Usage

maxBy calls getValue for each value in the piped array and returns the value with the largest result. If the array is empty, it returns undefined.

import { maxBy, pipe } from 'es-toolkit/fp';

pipe(
  [{ score: 10 }, { score: 30 }, { score: 20 }],
  maxBy(item => item.score)
); // => { score: 30 }

Parameters

getValue(item: T) => numberrequired

The function that returns the value used for comparison.

Returns

A function that maps a readonly T[] to the maximum item, or undefined.

(array: readonly T[]) => T | undefined
Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.