Last active
February 10, 2020 15:20
-
-
Save justinhj/14202ad9e34c8645767f225462ab6900 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.justinhj | |
import zio.blocking.Blocking | |
import zio.clock.Clock | |
import zio.console._ | |
import zio.random.Random | |
import zio.system.System | |
import zio.internal.PlatformLive | |
import zio.DefaultRuntime | |
import zio._ | |
import monix.eval | |
import zio.interop.monix._ | |
/* | |
I was wondering what the best way to convert from a ZIO[R,Throwable,A] to a Monix eval.Task is? | |
I cant seem to get the implicit conversions to work in zio-interop-monix? Do I have to remove | |
the environment from the effect somehow first? | |
Working through interop layers with ZIO and monix and cats io, for the most part | |
has been pretty seamless, but this one has me stumped a bit | |
*/ | |
object ZioAmmonite { | |
type Env = Clock with Console with System with Random with Blocking | |
import monix.execution.Scheduler.Implicits.global | |
// A runtime instance | |
implicit val rts: Runtime[Env] = new DefaultRuntime { | |
override val platform = | |
PlatformLive.makeDefault().withReportFailure(_ => ()) | |
} | |
def z1(n: Int) : ZIO[Env, Throwable, Int] = { | |
for ( | |
_ <- putStrLn(s"Hello with number $n") | |
) yield (n + 1) | |
} | |
val mio = z1(10).provide(rts.environment).toTask | |
val mioRan = rts.unsafeRun(mio) | |
def main(args: Array[String]): Unit = { | |
mioRan.runToFuture.foreach(r => println(s"IO to task result is $r")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment