<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"]export function function makeCombiner<
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"]
makeCombiner<function (type parameter) A in makeCombiner<A extends ReadonlyArray<unknown>>(combiners: { readonly [K in keyof A]: Combiner.Combiner<A[K]>; }): Combiner.Combiner<A>A extends interface ReadonlyArray<T>ReadonlyArray<unknown>>(
combiners: {
readonly [K in keyof A]: Combiner.Combiner<A[K]>
}
combiners: { readonly [function (type parameter) KK in keyof function (type parameter) A in makeCombiner<A extends ReadonlyArray<unknown>>(combiners: { readonly [K in keyof A]: Combiner.Combiner<A[K]>; }): Combiner.Combiner<A>A]: import CombinerCombiner.interface Combiner<A>Represents a strategy for combining two values of the same type A. A
Combiner contains a single combine method that takes two values and
returns a merged result. It does not include an identity/empty value; use
Reducer when you need one.
When to use
Use when you need to describe how two values of the same type
merge, pass a reusable combining strategy to library functions like
Struct.makeCombiner or Option.makeCombinerFailFast, or define the
combining step for a Reducer.
Example (Combining numbers with addition)
import { Combiner } from "effect"
const Sum = Combiner.make<number>((self, that) => self + that)
console.log(Sum.combine(3, 4))
// Output: 7
Combiner<function (type parameter) A in makeCombiner<A extends ReadonlyArray<unknown>>(combiners: { readonly [K in keyof A]: Combiner.Combiner<A[K]>; }): Combiner.Combiner<A>A[function (type parameter) KK]> }
): import CombinerCombiner.interface Combiner<A>Represents a strategy for combining two values of the same type A. A
Combiner contains a single combine method that takes two values and
returns a merged result. It does not include an identity/empty value; use
Reducer when you need one.
When to use
Use when you need to describe how two values of the same type
merge, pass a reusable combining strategy to library functions like
Struct.makeCombiner or Option.makeCombinerFailFast, or define the
combining step for a Reducer.
Example (Combining numbers with addition)
import { Combiner } from "effect"
const Sum = Combiner.make<number>((self, that) => self + that)
console.log(Sum.combine(3, 4))
// Output: 7
Combiner<function (type parameter) A in makeCombiner<A extends ReadonlyArray<unknown>>(combiners: { readonly [K in keyof A]: Combiner.Combiner<A[K]>; }): Combiner.Combiner<A>A> {
return import CombinerCombiner.function make<A>(
combine: (self: A, that: A) => A
): Combiner<A>
Creates a Combiner from a binary function.
When to use
Use when you have a custom combining operation that is not covered by
the built-in constructors (min, max, first, last, constant).
Details
The returned combiner's combine method delegates to the provided function.
Any purity, associativity, or mutation behavior comes from that function.
Example (Multiplying numbers)
import { Combiner } from "effect"
const Product = Combiner.make<number>((self, that) => self * that)
console.log(Product.combine(3, 5))
// Output: 15
make((self: A extends ReadonlyArray<unknown>self, that: A extends ReadonlyArray<unknown>that) => {
const const out: any[]out = []
for (let let i: numberi = 0; let i: numberi < self: A extends ReadonlyArray<unknown>self.ReadonlyArray<T>.length: numberGets the length of the array. This is a number one higher than the highest element defined in an array.
length; let i: numberi++) {
const out: any[]out.Array<any>.push(...items: any[]): numberAppends new elements to the end of an array, and returns the new length of the array.
push(combiners: {
readonly [K in keyof A]: Combiner.Combiner<A[K]>
}
combiners[let i: numberi].Combiner<unknown>.combine: (self: unknown, that: unknown) => unknownCombines two values into a new value.
When to use
Use to merge two values according to this combining strategy.
combine(self: A extends ReadonlyArray<unknown>self[let i: numberi], that: A extends ReadonlyArray<unknown>that[let i: numberi]))
}
return const out: unknown[]out as any
})
}