Skip to main content

Type Alias: RawReducerWithFinish<Value, Acc, Finished, This>

RawReducerWithFinish<Value, Acc, Finished, This>: RawReducerWithoutFinish<Value, Acc, This> & object

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.

Type declaration

finish()

finish: (this, acc) => Finished

Parameters

this

This

acc

Acc

Returns

Finished

Type Parameters

Value = unknown

Acc = Value

Finished = Acc

This = unknown

Example

import { pipe, reduce } from 'lfi'

console.log(
pipe(
[1, 2, 3, 4],
reduce(
// This is a `RawReducerWithFinish`
{
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:201