<A>(
reducers: { readonly [K in keyof A]: Reducer.Reducer<A[K]> },
options?: {
readonly omitKeyWhen?: ((a: A[keyof A]) => boolean) | undefined
}
): Reducer.Reducer<A>Creates a Reducer for a struct shape by providing a Reducer for each
property. The initial value is derived from each property's
Reducer.initialValue. When reducing a collection of structs, each property
is combined independently.
When to use
Use when you need to fold same-shape records by accumulating each property independently into one summary record.
Details
Pass omitKeyWhen to drop properties whose reduced value matches a
predicate.
Example (Reducing a collection of structs)
import { Number, String, Struct } from "effect"
const R = Struct.makeReducer<{ readonly n: number; readonly s: string }>({
n: Number.ReducerSum,
s: String.ReducerConcat
})
const result = R.combineAll([
{ n: 1, s: "a" },
{ n: 2, s: "b" },
{ n: 3, s: "c" }
])
console.log(result) // { n: 6, s: "abc" }export function function makeReducer<A>(
reducers: {
readonly [K in keyof A]: Reducer.Reducer<A[K]>
},
options?: {
readonly omitKeyWhen?:
| ((a: A[keyof A]) => boolean)
| undefined
}
): Reducer.Reducer<A>
Creates a Reducer for a struct shape by providing a Reducer for each
property. The initial value is derived from each property's
Reducer.initialValue. When reducing a collection of structs, each property
is combined independently.
When to use
Use when you need to fold same-shape records by accumulating each property
independently into one summary record.
Details
Pass omitKeyWhen to drop properties whose reduced value matches a
predicate.
Example (Reducing a collection of structs)
import { Number, String, Struct } from "effect"
const R = Struct.makeReducer<{ readonly n: number; readonly s: string }>({
n: Number.ReducerSum,
s: String.ReducerConcat
})
const result = R.combineAll([
{ n: 1, s: "a" },
{ n: 2, s: "b" },
{ n: 3, s: "c" }
])
console.log(result) // { n: 6, s: "abc" }
makeReducer<function (type parameter) A in makeReducer<A>(reducers: { readonly [K in keyof A]: Reducer.Reducer<A[K]>; }, options?: {
readonly omitKeyWhen?: ((a: A[keyof A]) => boolean) | undefined;
}): Reducer.Reducer<A>
A>(
reducers: {
readonly [K in keyof A]: Reducer.Reducer<A[K]>
}
reducers: { readonly [function (type parameter) KK in keyof function (type parameter) A in makeReducer<A>(reducers: { readonly [K in keyof A]: Reducer.Reducer<A[K]>; }, options?: {
readonly omitKeyWhen?: ((a: A[keyof A]) => boolean) | undefined;
}): Reducer.Reducer<A>
A]: import ReducerReducer.type Reducer.Reducer = /*unresolved*/ anyReducer<function (type parameter) A in makeReducer<A>(reducers: { readonly [K in keyof A]: Reducer.Reducer<A[K]>; }, options?: {
readonly omitKeyWhen?: ((a: A[keyof A]) => boolean) | undefined;
}): Reducer.Reducer<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 makeReducer<A>(reducers: { readonly [K in keyof A]: Reducer.Reducer<A[K]>; }, options?: {
readonly omitKeyWhen?: ((a: A[keyof A]) => boolean) | undefined;
}): Reducer.Reducer<A>
A[keyof function (type parameter) A in makeReducer<A>(reducers: { readonly [K in keyof A]: Reducer.Reducer<A[K]>; }, options?: {
readonly omitKeyWhen?: ((a: A[keyof A]) => boolean) | undefined;
}): Reducer.Reducer<A>
A]) => boolean) | undefined
}
): import ReducerReducer.type Reducer.Reducer = /*unresolved*/ anyReducer<function (type parameter) A in makeReducer<A>(reducers: { readonly [K in keyof A]: Reducer.Reducer<A[K]>; }, options?: {
readonly omitKeyWhen?: ((a: A[keyof A]) => boolean) | undefined;
}): Reducer.Reducer<A>
A> {
const const combine: anycombine = 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(reducers: {
readonly [K in keyof A]: Reducer.Reducer<A[K]>
}
reducers, options: | {
readonly omitKeyWhen?:
| ((a: A[keyof A]) => boolean)
| undefined
}
| undefined
options).combine
const const initialValue: AinitialValue = {} as function (type parameter) A in makeReducer<A>(reducers: { readonly [K in keyof A]: Reducer.Reducer<A[K]>; }, options?: {
readonly omitKeyWhen?: ((a: A[keyof A]) => boolean) | undefined;
}): Reducer.Reducer<A>
A
for (const const key: keyof Akey of 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(reducers: {
readonly [K in keyof A]: Reducer.Reducer<A[K]>
}
reducers) as interface Array<T>Array<keyof function (type parameter) A in makeReducer<A>(reducers: { readonly [K in keyof A]: Reducer.Reducer<A[K]>; }, options?: {
readonly omitKeyWhen?: ((a: A[keyof A]) => boolean) | undefined;
}): Reducer.Reducer<A>
A>) {
const const iv: anyiv = reducers: {
readonly [K in keyof A]: Reducer.Reducer<A[K]>
}
reducers[const key: keyof Akey].initialValue
if (options: | {
readonly omitKeyWhen?:
| ((a: A[keyof A]) => boolean)
| undefined
}
| undefined
options?.omitKeyWhen?: ((a: A[keyof A]) => boolean) | undefinedomitKeyWhen?.(const iv: anyiv)) continue
const initialValue: AinitialValue[const key: keyof Akey] = const iv: anyiv
}
return import ReducerReducer.make(const combine: anycombine, const initialValue: AinitialValue)
}