minimalistic cache
May. 3rd, 2025 05:51 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
isFinite
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)
no subject
Date: 2025-05-03 04:47 pm (UTC)no subject
Date: 2025-05-03 07:00 pm (UTC)