diff --git a/core/shared/src/main/scala/dev/tauri/choam/refs/RefLike.scala b/core/shared/src/main/scala/dev/tauri/choam/refs/RefLike.scala index d81631581..d2e8b1c06 100644 --- a/core/shared/src/main/scala/dev/tauri/choam/refs/RefLike.scala +++ b/core/shared/src/main/scala/dev/tauri/choam/refs/RefLike.scala @@ -29,10 +29,12 @@ trait RefLike[A] { def updWith[B, C](f: (A, B) => Axn[(A, C)]): Rxn[B, C] - // derived (but overridden for performance): + // derivable (but primitive for performance): - def upd[B, C](f: (A, B) => (A, C)): Rxn[B, C] = - updWith[B, C] { (a, b) => Axn.pure(f(a, b)) } + def upd[B, C](f: (A, B) => (A, C)): Rxn[B, C] + // Note: in theory this could be implemented as + // `updWith[B, C] { (a, b) => Axn.pure(f(a, b)) }`, + // but we rather have it as a primitive. // derived: diff --git a/data/jvm/src/main/scala/dev/tauri/choam/data/Ttrie.scala b/data/jvm/src/main/scala/dev/tauri/choam/data/Ttrie.scala index 05fd1eec4..0e19f5e3f 100644 --- a/data/jvm/src/main/scala/dev/tauri/choam/data/Ttrie.scala +++ b/data/jvm/src/main/scala/dev/tauri/choam/data/Ttrie.scala @@ -274,7 +274,8 @@ private final class Ttrie[K, V] private ( final def get: Axn[V] = self.get.provide(key).map(_.getOrElse(default)) - // TODO: maybe override `upd` and/or `getAndSet` if we can make it faster than the default impl. + final def upd[B, C](f: (V, B) => (V, C)): B =#> C = + updWith[B, C] { (v, b) => Axn.pure(f(v, b)) } final def updWith[B, C](f: (V, B) => Axn[(V, C)]): B =#> C = { getRefWithKey(key).flatMap { ref => diff --git a/data/shared/src/main/scala/dev/tauri/choam/data/SimpleMap.scala b/data/shared/src/main/scala/dev/tauri/choam/data/SimpleMap.scala index 147287ea1..cd786290b 100644 --- a/data/shared/src/main/scala/dev/tauri/choam/data/SimpleMap.scala +++ b/data/shared/src/main/scala/dev/tauri/choam/data/SimpleMap.scala @@ -103,7 +103,7 @@ private final class SimpleMap[K, V] private ( final def get: Axn[V] = self.get.provide(key).map(_.getOrElse(default)) - final override def upd[B, C](f: (V, B) => (V, C)): B =#> C = { + final def upd[B, C](f: (V, B) => (V, C)): B =#> C = { Rxn.computed[B, C] { (b: B) => repr.modify { hm => val currVal = hm.getOrElse(key, default) diff --git a/data/shared/src/main/scala/dev/tauri/choam/data/SimpleOrderedMap.scala b/data/shared/src/main/scala/dev/tauri/choam/data/SimpleOrderedMap.scala index 4201bb153..cb15acf1a 100644 --- a/data/shared/src/main/scala/dev/tauri/choam/data/SimpleOrderedMap.scala +++ b/data/shared/src/main/scala/dev/tauri/choam/data/SimpleOrderedMap.scala @@ -105,7 +105,7 @@ private final class SimpleOrderedMap[K, V] private ( final def get: Axn[V] = self.get.provide(key).map(_.getOrElse(default)) - final override def upd[B, C](f: (V, B) => (V, C)): B =#> C = { + final def upd[B, C](f: (V, B) => (V, C)): B =#> C = { Rxn.computed[B, C] { (b: B) => repr.modify { am => val currVal = am.get(key).getOrElse(default)