Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ApplicativeAsk with subtyping #232

Merged
merged 2 commits into from
Oct 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions interop-cats/shared/src/main/scala/zio/interop/catsmtl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ abstract class CatsMtlInstances {
def local[A](f: R => R)(fa: ZIO[R, E, A]): ZIO[R, E, A] = ZIO.accessM(fa provide f(_))
}

implicit def zioApplicativeAsk[R1, R <: R1, E](
implicit ev: Applicative[ZIO[R, E, ?]]
): ApplicativeAsk[ZIO[R, E, ?], R1] =
new DefaultApplicativeAsk[ZIO[R, E, ?], R1] {
override val applicative: Applicative[ZIO[R, E, *]] = ev
override def ask: ZIO[R, Nothing, R1] = ZIO.environment
}

implicit def zioApplicativeHandle[R, E](implicit ev: Applicative[ZIO[R, E, ?]]): ApplicativeHandle[ZIO[R, E, ?], E] =
new DefaultApplicativeHandle[ZIO[R, E, ?], E] {
val functor: Functor[ZIO[R, E, ?]] = ev
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ class catzMtlSpec extends catzSpecZIOBase {
implicit tc => ApplicativeHandleTests[ZIO[Ctx, Error, *], Error].applicativeHandle[Int]
)

def askSummoner[R, E] = ApplicativeAsk[ZIO[R, E, *], R]
def localSummoner[R, E] = ApplicativeLocal[ZIO[R, E, *], R]
def raiseSummoner[R, E] = FunctorRaise[ZIO[R, E, *], E]
def handleSummoner[R, E] = ApplicativeHandle[ZIO[R, E, *], E]
def askSummoner[R, E] = ApplicativeAsk[ZIO[R, E, *], R]
def askSubtypingSummoner[R1, R <: R1, E] = ApplicativeAsk[ZIO[R, E, *], R1]
def localSummoner[R, E] = ApplicativeLocal[ZIO[R, E, *], R]
def raiseSummoner[R, E] = FunctorRaise[ZIO[R, E, *], E]
def handleSummoner[R, E] = ApplicativeHandle[ZIO[R, E, *], E]
}