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

Function collectAllToMap

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

Source from the content-addressed store, hash-verified

122
123/** @internal */
124export const collectAllToMap = <In, K>(
125 key: (input: In) => K,
126 merge: (x: In, y: In) => In
127): Sink.Sink<HashMap.HashMap<K, In>, In> => {
128 return foldLeftChunks(HashMap.empty<K, In>(), (map, chunk) =>
129 pipe(
130 chunk,
131 Chunk.reduce(map, (map, input) => {
132 const k: K = key(input)
133 const v: In = pipe(map, HashMap.has(k)) ?
134 merge(pipe(map, HashMap.unsafeGet(k)), input) :
135 input
136 return pipe(map, HashMap.set(k, v))
137 })
138 ))
139}
140
141/** @internal */
142export const collectAllToMapN = <In, K>(

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected