Last active
August 26, 2021 22:15
-
-
Save mpilquist/0b1cc1926bddd31c70ad40663acfec8e to your computer and use it in GitHub Desktop.
Ammonite REPL predef for use with fs2
This file contains 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
// Save as ~/.ammonite/predef.sc | |
// To use fs2 from ammonite repl, type `load.fs2` from repl prompt. | |
// You'll get all fs2 & cats imports, ContextShift and Timer instances | |
// for IO, and a globalBlocker | |
import $plugin.$ivy.`org.typelevel:::kind-projector:0.11.0` | |
if (!repl.compiler.settings.isScala213) | |
repl.load.apply("interp.configureCompiler(_.settings.YpartialUnification.value = true)") | |
interp.configureCompiler(_.settings.Ydelambdafy.tryToSetColon(List("inline"))) | |
object load { | |
def fs2Version(version: String) = { | |
repl.load.apply(s""" | |
import $$ivy.`co.fs2::fs2-io:$version`, fs2._, fs2.concurrent._, cats._, cats.implicits._, cats.effect._, cats.effect.implicits._, scala.concurrent.duration._ | |
implicit val ioContextShift: ContextShift[IO] = IO.contextShift(scala.concurrent.ExecutionContext.Implicits.global) | |
implicit val ioTimer: Timer[IO] = IO.timer(scala.concurrent.ExecutionContext.Implicits.global) | |
""") | |
if (!version.startsWith("1")) repl.load.apply(""" | |
val globalBlocker: Blocker = cats.effect.Blocker.liftExecutionContext(scala.concurrent.ExecutionContext.Implicits.global) | |
""") | |
} | |
def fs2 = fs2Version("2.0.1") | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I get an error on line 8 occasionally with this predef.