Hyperlinkv0.8.0-beta.28

Tuple

Tuple.makeCombinerfunctioneffect/Tuple.ts:683
<A extends ReadonlyArray<unknown>>(combiners: {
  readonly [K in keyof A]: Combiner.Combiner<A[K]>
}): Combiner.Combiner<A>

Creates a Combiner for a tuple shape by providing a Combiner for each position. When two tuples are combined, each element is merged using its corresponding combiner.

When to use

Use when you need to merge two same-shape tuples by combining each position independently, such as summing counters or concatenating strings.

Example (Combining tuple elements)

import { Number, String, Tuple } from "effect"

const C = Tuple.makeCombiner<readonly [number, string]>([
  Number.ReducerSum,
  String.ReducerConcat
])

const result = C.combine([1, "hello"], [2, " world"])
console.log(result) // [3, "hello world"]
combiningmakeReducer
Source effect/Tuple.ts:68311 lines
export function makeCombiner<A extends ReadonlyArray<unknown>>(
  combiners: { readonly [K in keyof A]: Combiner.Combiner<A[K]> }
): Combiner.Combiner<A> {
  return Combiner.make((self, that) => {
    const out = []
    for (let i = 0; i < self.length; i++) {
      out.push(combiners[i].combine(self[i], that[i]))
    }
    return out as any
  })
}
Referenced by 1 symbols