| 140 | |
| 141 | /** @internal */ |
| 142 | export 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 */ |
| 162 | export const collectAllToSet = <In>(): Sink.Sink<HashSet.HashSet<In>, In> => |