Skip to main content

Type Alias: Reducer<Value, Acc, Finished>

Reducer<Value, Acc, Finished>: RawReducerWithFinish<Value, Acc, Finished>

A reducer that reduces by creating an initial accumulator using RawReducerWithoutFinish.create, then adding values to the accumulator values using RawReducerWithoutFinish.add, and then transforming the final accumulator using RawReducerWithFinish.finish.

It's identical to RawReducerWithFinish except its this is bound by normalizeReducer.

Type Parameters

Value = unknown

Acc = Value

Finished = Acc

Example

import { pipe, reduce } from 'lfi'

console.log(
pipe(
[1, 2, 3, 4],
reduce(
// This will be a `Reducer` once it's normalized by `reduce`
{
create: () => 0,
add: (number1, number2) => number1 + number2,
finish: sum => `The sum is ${sum}`,
},
),
),
)
//=> The sum is 10
Playground

Since

v2.0.0

Defined in

reducers.d.ts:242