MCPcopy Index your code
hub / github.com/Effect-TS/effect / collectAllToMapN

Function collectAllToMapN

packages/effect/src/internal/sink.ts:142–159  ·  view source on GitHub ↗
(
  n: number,
  key: (input: In) => K,
  merge: (x: In, y: In) => In
)

Source from the content-addressed store, hash-verified

140
141/** @internal */
142export const collectAllToMapN = <In, K>(
143 n: number,
144 key: (input: In) => K,
145 merge: (x: In, y: In) => In
146): Sink.Sink<HashMap.HashMap<K, In>, In, In> => {
147 return foldWeighted<HashMap.HashMap<K, In>, In>({
148 initial: HashMap.empty(),
149 maxCost: n,
150 cost: (acc, input) => pipe(acc, HashMap.has(key(input))) ? 0 : 1,
151 body: (acc, input) => {
152 const k: K = key(input)
153 const v: In = pipe(acc, HashMap.has(k)) ?
154 merge(pipe(acc, HashMap.unsafeGet(k)), input) :
155 input
156 return pipe(acc, HashMap.set(k, v))
157 }
158 })
159}
160
161/** @internal */
162export const collectAllToSet = <In>(): Sink.Sink<HashSet.HashSet<In>, In> =>

Callers

nothing calls this directly

Calls 6

foldWeightedFunction · 0.85
unsafeGetMethod · 0.80
pipeFunction · 0.70
mergeFunction · 0.70
setMethod · 0.65
keyFunction · 0.50

Tested by

no test coverage detected