Skip to content

on

on<A, B, C>(f, g): (a, b) => C

Defined in: Composition/on.ts:13

Applies a projection to both arguments of a binary function before calling it. Most useful for building comparators and equality checks over projected values.

A

B

C

(b1, b2) => C

(a) => B

(a, b): C

A

A

C

const byLength = on((a: number, b: number) => a - b, (s: string) => s.length);

["banana", "fig", "apple"].sort(byLength); // ["fig", "apple", "banana"]