Package: effect
Module: Reducer
Represents a strategy for reducing a collection of values of type A into
a single result.
When to use
Use when you need to fold/reduce a collection into a single value.
Struct.makeReducer, Option.makeReducer, or
Record.makeReducerUnion.Details
Extends Combiner.Combiner with:
initialValue – the identity/neutral element for combine.combineAll – folds an entire Iterable<A> from initialValue.Many modules ship pre-built reducers:
Number.ReducerSum, Number.ReducerMultiplyString.ReducerConcatBoolean.ReducerAnd, Boolean.ReducerOrExample (String concatenation reducer)
import { Reducer } from "effect"
const Concat = Reducer.make<string>((a, b) => a + b, "")
console.log(Concat.combineAll(["hello", " ", "world"]))
// Output: "hello world"
See
make – create a Reducer from a function and initial valueCombiner.Combiner – parent interface without initialValueSignature
export interface Reducer<A> extends Combiner.Combiner<A> {
/**
* Neutral starting value (combining with this changes nothing).
*
* **When to use**
*
* Use to seed a reduction and represent the result of reducing an empty collection.
*/
readonly initialValue: A
/**
* Combines all values in the collection, starting from `initialValue`.
*
* **When to use**
*
* Use to reduce an iterable with this reducer's initial value and combining operation.
*/
readonly combineAll: (collection: Iterable<A>) => A
}
Since v4.0.0