Learn
FP Learn
Foundations of Functional Programming - Wikiversity
Foundations of Functional Programming/The λ-cube - Wikiversity
Разобраться как это работает (интероп между Бифунктором BIO и MonadError
Context Bound
It shouldn’t be surprising that context bounds are implemented with implicit parameters, given their definition. Actually, the syntax I showed are syntactic sugars for what really happens. See below how they de-sugar:
def g[A : B](a: A) = h(a)
def g[A](a: A)(implicit ev: B[A]) = h(a)
Not works
def t[
F[+_,+_]: izumi.functional.bio.BIOPrimitives: izumi.functional.bio.BIO,
R[_] : Sync : MonadError[Throwable, ?]]
(t: R[Int])(implicit s: MonadError[F[Throwable, ?], Throwable]): F[Throwable, Int]
= s.pure(10/1)
Works
import $plugin.$ivy.`org.typelevel:kind-projector_2.13.2:0.11.0`
import scala.concurrent.ExecutionContext.global
import doobie.util.ExecutionContexts
import izumi.functional._
import izumi.functional.bio._
~~i~~mport izumi.functional.bio.catz._
import cats._, cats.effect._, cats.implicits._
implicit val cs: ContextShift[IO] = IO.contextShift(ExecutionContexts.synchronous)
def t[F[+_,+_]: izumi.functional.bio.BIOPrimitives: izumi.functional.bio.BIO : izumi.functional.bio.BIOApplicative, R[_] : Sync :MonadError[?[_], Throwable], B](t: R[B])(implicit s: MonadError[R, Throwable]): F[Throwable, Int] = MonadError[F[Throwable, ?], Throwable].pure(10 / 0)
t(IO(1/0))
def t[F[+_, +_]: BIOPrimitives: BIO, R[_]: Effect, B](t: R[B])(implicit cs: ContextShift[R]): F[Throwable, B] = {
Concurrent[F[Throwable, ?]].liftIO(Effect[R].toIO(t))
}
Welcome to Chimney's documentation! - Chimney 0.5.2 documentation
Kai @neko-kai May 21 23:36
@Jacke If R[_] is a different type that isn't F[Throwable, ?], you could do it like this:
def t[F[+_, +_]: BIOAsync: BIOFork, R[_]: Effect, B](t: R[B]): F[Throwable, B] = {
import izumi.functional.bio.catz._
Concurrent[F[Throwable, ?]].liftIO(Effect[R].toIO(t))
}
t[zio.IO, cats.effect.IO, Int](cats.effect.IO(1))
def from[F[+_, +_]: BIOAsync: BIOFork, R[_]: Concurrent: ContextShift: Effect, B](t: F[_, B]): R[B] = {
import izumi.functional.bio.catz._
Effect[R].liftIO(Concurrent[F[Throwable, ?]].toIO(t))
}
def toCatsEffect[F[+_], R, A](zio: RIO[R, A])(implicit R: Runtime[R], F: LiftIO[F]): F[A] =
F.liftIO(taskEffectInstance.toIO(zio))
toCatsEffect[cats.effect.IO, Any, Int](res14)
implicit class RichZIO[F[+_], R, A](val self: RIO[R, A])(implicit R: Runtime[R], F: LiftIO[F]) extends AnyVal {
def toCatsEffect[F[+_], R, A]: F[A] = F.liftIO(taskEffectInstance.toIO(self))
}
// WORKS
implicit class SmellyZI[F[+_, +_]: BIOAsync: BIOFork, R[_]: Effect, B](t: R[B]) {
def t: F[Throwable, B] = {
import izumi.functional.bio.catz._
Concurrent[F[Throwable, ?]].liftIO(Effect[R].toIO(t))
}
}
implicit class SmellyCattyyy[F[+_], R, A](zio: ZIO[R, Throwable, A])(implicit R: Runtime[R], F: LiftIO[F]) {
def toCatsEffect: F[A] =
F.liftIO(taskEffectInstance.toIO(zio))
}
8.1 The Future of Machine Learning | Interpretable Machine Learning
Building a cool CLI with Decline for my ZIO App
Building the Death Star with ZIO Stream
Dependency injection with Reader Monad in Scala
Scala-cats, compose Reader with ReaderT
Typelevel.scala | A comprehensive introduction to Cats-mtl
https://gist.github.com/jackcviers/804b6d8d1b2ead210367a104a746fd00
ZIO & Cats Effect: удачный союз
Replacing Akka Actors with Cats Effect and FS2
Typelevel.scala | Tagless Final algebras and Streaming
Cats Effect 3.0 Proposal · Issue #634 · typelevel/cats-effect
Cats Effect 3.0 Design Discussion · Issue #321 · typelevel/cats-effect
What does the #
operator mean in Scala?
herding cats - Checking laws with Discipline