Hyperlinkv0.8.0-beta.28

Record

Record.makeReducerIntersectionfunctioneffect/Record.ts:1504
<K extends string, A>(combiner: Combiner.Combiner<A>): Reducer.Reducer<
  Record<K, A>
>

Creates a Reducer whose combine operation intersects two records and combines values for keys present in both records.

When to use

Use to build a Reducer that combines records by retaining only keys shared by both inputs and combining matching values with a Combiner.

Gotchas

The reducer's initialValue is an empty record. Because intersection with an empty record is empty, the default combineAll folds from {} and therefore produces {} for ordinary non-empty inputs.

Source effect/Record.ts:15048 lines
export function makeReducerIntersection<K extends string, A>(
  combiner: Combiner.Combiner<A>
): Reducer.Reducer<Record<K, A>> {
  return Reducer.make(
    (self, that) => intersection(self, that, combiner.combine) as any,
    {} as Record<K, A>
  )
}