Skip to main content

Type Alias: OptionalReducer<Value, Finished>

OptionalReducer<Value, Finished>: RawOptionalReducerWithFinish<Value, Finished>

A reducer that reduces by combining pairs of values using RawOptionalReducerWithoutFinish.add and then transforming the final value using RawOptionalReducerWithFinish.finish.

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

Type Parameters

Value = unknown

Finished = Value

Example

import { or, pipe, reduce } from 'lfi'

console.log(
pipe(
[1, 2, 3, 4],
reduce(
// This will be an `OptionalReducer` once it's normalized by `reduce`
{
add: (number1, number2) => number1 + number2,
finish: sum => `The sum is ${sum}`,
},
),
or(() => `There are no numbers`),
),
)
//=> The sum is 10
Playground

Since

v2.0.0

Defined in

reducers.d.ts:131