βReducer
Reducer
Examples:
Reducer with selector and implicit type comparator
const people = [
{ name: 'Alice', age: 30 },
{ name: 'Bob', age: 25 },
{ name: 'Charlie', age: 35 }
];
const reducer = reducerOf(people);
const minByAge = reducer.minBy((person) => person.age);
console.log(minByAge);
// Output: { name: 'Bob', age: 25 }Reducer with selector and custom comparator
const people = [
{ name: 'Alice', age: 30 },
{ name: 'Bob', age: 25 },
{ name: 'Charlie', age: 35 }
];
const minOfAge = reducerOf(people).minOfWith((person) => person.age, (a, b) => a - b);
console.log(minOfAge);
// Output: { name: 'Bob', age: 25 }Running reducer
Last updated