/** * If the key `k` is not already associated with a value, stores the provided * value, otherwise merge the existing value with the new one using function * `f` and store the result * * @tsplus static effect/core/stm/TMap.Aspects merge * @tsplus pipeable effect/core/stm/TMap merge */ export function merge_(k: K, v: V, f: (values: readonly [V, V]) => V) { return (self: TMap): STM => self.get(k).flatMap((_) => _.fold(self.put(k, v).as(v), (v0) => { const v1 = f([v0, v]) return self.put(k, v1).as(v1) }) ) }