effect-io-ai

Package: effect
Module: Reducer

Reducer.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.

Details

Extends Combiner.Combiner with:

Many modules ship pre-built reducers:

Example (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

Signature

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
}

Source

Since v4.0.0