Skip to content

Instantly share code, notes, and snippets.

@SystemFw
SystemFw / RankN shift-and-shiftback.md
Last active June 1, 2019 03:15
Cats-effect, blocking, RankN-types.

cats-effect

The cats-effect project defines a purely functional effect type (IO[A]), and associated typeclasses defining its behaviour. The ones we care about for this example are:

trait Sync[F[_]] extends MonadError[F, Throwable] {
   def delay[A](a: => A): F[A]
   ...
}
@neko-kai
neko-kai / quantified.scala
Last active April 2, 2019 13:53
Tagless final for ZIO via quantified constraints
package quantified
import cats.Monad
import scala.language.implicitConversions
/**
* C[_] constraint applied to type F[_, _] quantified in first parameter, i.e.
*
* {{{
object Cached {
def create[F[_]: Concurrent, A](fa: F[A], ttl: FiniteDuration)(implicit t: Timer[F]): F[Cached[F, A]] = {
sealed trait State
case class Value(v: A, ts: Long) extends State
case class Updating(d: Deferred[F, Either[Throwable, A]]) extends State
case object NoValue extends State
def currentTimestamp = t.clock.monotonic(ttl.unit)
Ref.of[F, State](NoValue).map { state =>
new Cached[F, A] {