<A>(
combiners: { readonly [K in keyof A]: Combiner.Combiner<A[K]> },
options?: {
readonly omitKeyWhen?: ((a: A[keyof A]) => boolean) | undefined
}
): Combiner.Combiner<A>Creates a Combiner for a struct shape by providing a Combiner for each
property. When two structs are combined, each property is merged using its
corresponding combiner.
When to use
Use when you need to merge two same-shape records by combining each property independently, such as summing counters or concatenating strings.
Details
Pass omitKeyWhen to drop properties whose merged value matches a predicate,
such as omitting zero counters.
Example (Combining struct properties)
import { Number, String, Struct } from "effect"
const C = Struct.makeCombiner<{ readonly n: number; readonly s: string }>({
n: Number.ReducerSum,
s: String.ReducerConcat
})
const result = C.combine({ n: 1, s: "hello" }, { n: 2, s: " world" })
console.log(result) // { n: 3, s: "hello world" }export function function makeCombiner<A>(
combiners: {
readonly [K in keyof A]: Combiner.Combiner<
A[K]
>
},
options?: {
readonly omitKeyWhen?:
| ((a: A[keyof A]) => boolean)
| undefined
}
): Combiner.Combiner<A>
Creates a Combiner for a struct shape by providing a Combiner for each
property. When two structs are combined, each property is merged using its
corresponding combiner.
When to use
Use when you need to merge two same-shape records by combining each property
independently, such as summing counters or concatenating strings.
Details
Pass omitKeyWhen to drop properties whose merged value matches a predicate,
such as omitting zero counters.
Example (Combining struct properties)
import { Number, String, Struct } from "effect"
const C = Struct.makeCombiner<{ readonly n: number; readonly s: string }>({
n: Number.ReducerSum,
s: String.ReducerConcat
})
const result = C.combine({ n: 1, s: "hello" }, { n: 2, s: " world" })
console.log(result) // { n: 3, s: "hello world" }
makeCombiner<function (type parameter) A in makeCombiner<A>(combiners: { readonly [K in keyof A]: Combiner.Combiner<A[K]>; }, options?: {
readonly omitKeyWhen?: ((a: A[keyof A]) => boolean) | undefined;
}): Combiner.Combiner<A>
A>(
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>(combiners: { readonly [K in keyof A]: Combiner.Combiner<A[K]>; }, options?: {
readonly omitKeyWhen?: ((a: A[keyof A]) => boolean) | undefined;
}): Combiner.Combiner<A>
A]: import CombinerCombiner.type Combiner.Combiner = /*unresolved*/ anyCombiner<function (type parameter) A in makeCombiner<A>(combiners: { readonly [K in keyof A]: Combiner.Combiner<A[K]>; }, options?: {
readonly omitKeyWhen?: ((a: A[keyof A]) => boolean) | undefined;
}): Combiner.Combiner<A>
A[function (type parameter) KK]> },
options: | {
readonly omitKeyWhen?:
| ((a: A[keyof A]) => boolean)
| undefined
}
| undefined
options?: {
readonly omitKeyWhen?: ((a: A[keyof A]) => boolean) | undefinedomitKeyWhen?: ((a: A[keyof A]a: function (type parameter) A in makeCombiner<A>(combiners: { readonly [K in keyof A]: Combiner.Combiner<A[K]>; }, options?: {
readonly omitKeyWhen?: ((a: A[keyof A]) => boolean) | undefined;
}): Combiner.Combiner<A>
A[keyof function (type parameter) A in makeCombiner<A>(combiners: { readonly [K in keyof A]: Combiner.Combiner<A[K]>; }, options?: {
readonly omitKeyWhen?: ((a: A[keyof A]) => boolean) | undefined;
}): Combiner.Combiner<A>
A]) => boolean) | undefined
}
): import CombinerCombiner.type Combiner.Combiner = /*unresolved*/ anyCombiner<function (type parameter) A in makeCombiner<A>(combiners: { readonly [K in keyof A]: Combiner.Combiner<A[K]>; }, options?: {
readonly omitKeyWhen?: ((a: A[keyof A]) => boolean) | undefined;
}): Combiner.Combiner<A>
A> {
const const omitKeyWhen: (
a: A[keyof A]
) => boolean
omitKeyWhen = options: | {
readonly omitKeyWhen?:
| ((a: A[keyof A]) => boolean)
| undefined
}
| undefined
options?.omitKeyWhen?: ((a: A[keyof A]) => boolean) | undefinedomitKeyWhen ?? (() => false)
return import CombinerCombiner.make((self: anyself, that: anythat) => {
const const keys: (keyof A)[]keys = Reflect.function Reflect.ownKeys(target: object): (string | symbol)[]Returns the string and symbol keys of the own properties of an object. The own properties of an object
are those that are defined directly on that object, and are not inherited from the object's prototype.
ownKeys(combiners: {
readonly [K in keyof A]: Combiner.Combiner<A[K]>
}
combiners) as interface Array<T>Array<keyof function (type parameter) A in makeCombiner<A>(combiners: { readonly [K in keyof A]: Combiner.Combiner<A[K]>; }, options?: {
readonly omitKeyWhen?: ((a: A[keyof A]) => boolean) | undefined;
}): Combiner.Combiner<A>
A>
const const out: Aout = {} as function (type parameter) A in makeCombiner<A>(combiners: { readonly [K in keyof A]: Combiner.Combiner<A[K]>; }, options?: {
readonly omitKeyWhen?: ((a: A[keyof A]) => boolean) | undefined;
}): Combiner.Combiner<A>
A
for (const const key: keyof Akey of const keys: (keyof A)[]keys) {
const const merge: anymerge = combiners: {
readonly [K in keyof A]: Combiner.Combiner<A[K]>
}
combiners[const key: keyof Akey].combine(self: anyself[const key: keyof Akey], that: anythat[const key: keyof Akey])
if (const omitKeyWhen: (
a: A[keyof A]
) => boolean
omitKeyWhen(const merge: anymerge)) continue
const out: Aout[const key: keyof Akey] = const merge: anymerge
}
return const out: Aout
})
}