MCPcopy Create free account
hub / github.com/Effect-TS/effect / makeReducer

Function makeReducer

packages/effect/src/Struct.ts:940–954  ·  view source on GitHub ↗
(
  reducers: { readonly [K in keyof A]: Reducer.Reducer<A[K]> },
  options?: {
    readonly omitKeyWhen?: ((a: A[keyof A]) => boolean) | undefined
  }
)

Source from the content-addressed store, hash-verified

938 * @since 4.0.0
939 */
940export function makeReducer<A>(
941 reducers: { readonly [K in keyof A]: Reducer.Reducer<A[K]> },
942 options?: {
943 readonly omitKeyWhen?: ((a: A[keyof A]) => boolean) | undefined
944 }
945): Reducer.Reducer<A> {
946 const combine = makeCombiner(reducers, options).combine
947 const initialValue = {} as A
948 for (const key of Reflect.ownKeys(reducers) as Array<keyof A>) {
949 const iv = reducers[key].initialValue
950 if (options?.omitKeyWhen?.(iv)) continue
951 InternalRecord.assignProperty(initialValue as object, key, iv)
952 }
953 return Reducer.make(combine, initialValue)
954}
955
956/**
957 * Creates a record with the given keys and value.

Callers

nothing calls this directly

Calls 2

makeCombinerFunction · 0.70
makeMethod · 0.65

Tested by

no test coverage detected