From ca14958b3fecec5abfc29997c146874380994431 Mon Sep 17 00:00:00 2001 From: Mark Canlas Date: Mon, 22 Jul 2024 22:30:43 -0400 Subject: [PATCH] drop memoization --- .../com/htmlism/spawningpool/package.scala | 11 -------- .../htmlism/spawningpool/PackageSpec.scala | 27 ------------------- 2 files changed, 38 deletions(-) delete mode 100644 spawning-pool-core/src/test/scala/com/htmlism/spawningpool/PackageSpec.scala diff --git a/spawning-pool-core/src/main/scala/com/htmlism/spawningpool/package.scala b/spawning-pool-core/src/main/scala/com/htmlism/spawningpool/package.scala index 698d9c5..37699df 100644 --- a/spawning-pool-core/src/main/scala/com/htmlism/spawningpool/package.scala +++ b/spawning-pool-core/src/main/scala/com/htmlism/spawningpool/package.scala @@ -16,17 +16,6 @@ package object spawningpool { implicit def countToInt(count: PositiveCount): Int = count.count - def memoize[A, B](f: A => B): A => B = { - val cache = collection.mutable.Map[A, B]() - - { key => - if (!cache.contains(key)) - cache(key) = f(key) - - cache(key) - } - } - implicit val asdf: Mutation[Int] = IntMutation implicit class MutationOps[A: Mutation](x: A) { diff --git a/spawning-pool-core/src/test/scala/com/htmlism/spawningpool/PackageSpec.scala b/spawning-pool-core/src/test/scala/com/htmlism/spawningpool/PackageSpec.scala deleted file mode 100644 index c9254a5..0000000 --- a/spawning-pool-core/src/test/scala/com/htmlism/spawningpool/PackageSpec.scala +++ /dev/null @@ -1,27 +0,0 @@ -package com.htmlism.spawningpool - -import org.specs2.mutable.Specification - -class PackageSpec extends Specification { - "Memoization" should { - "prevent side-effects on subsequent applications" in { - val scratch = collection.mutable.Map[Symbol, Int]().withDefaultValue(0) - - val originalFunction = { key: String => - scratch(key) = scratch(key) + 1 - } - - val memoizedFunction = memoize(originalFunction) - - memoizedFunction("pauper") - scratch === Map("pauper" -> 1) - - memoizedFunction("pauper") - scratch === Map("pauper" -> 1) - - originalFunction("prince") - originalFunction("prince") - scratch == Map("pauper" -> 1, "prince" -> 2) // smart equality operator not so smart on disparate constructions? - } - } -}