type CacheT[F[_], K, V] = StateT[F, Map[K, V], V]
def lift[F[_]: Applicative, K, V](fetch: K => F[V]): K => CacheT[F, K, V] =
k => StateT(cache => {
cache.get(k) match {
case Some(v) => (cache, v).point[F]
case None => fetch(k) map { v => (cache + (k -> v), v) }
}
})
--
You received this message because you are subscribed to the Google Groups "scalaz" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalaz+un...@googlegroups.com.
To post to this group, send email to sca...@googlegroups.com.
Visit this group at http://groups.google.com/group/scalaz.
For more options, visit https://groups.google.com/d/optout.
Thanks, Tomas!
I'm all for minimal type requirements, I just didn't know if there might be some other issue I wasn't considering.
Cheers,
Derek
You received this message because you are subscribed to a topic in the Google Groups "scalaz" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/scalaz/D3onUKvvaRw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to scalaz+un...@googlegroups.com.
You received this message because you are subscribed to a topic in the Google Groups "scalaz" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/scalaz/D3onUKvvaRw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to scalaz+un...@googlegroups.com.