minimalistic cache
May. 3rd, 2025 05:51 pmisFinite
tells us whether we can cache it; maybe it's coming from a predicate that checks the size, or something.class Cache[K,V](isFinite: Boolean, build: K => V): private val cache: mutable.Map[K, V] = mutable.Map[K, V]() private val app: K => V = if (isFinite) (k: K) => cache.getOrElseUpdate(k, build(k)) else (k: K) => build(k) inline def apply(k: K): V = app(k)