Skip to content

Instantly share code, notes, and snippets.

@mpilquist
Last active August 26, 2021 22:15
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save mpilquist/0b1cc1926bddd31c70ad40663acfec8e to your computer and use it in GitHub Desktop.
Save mpilquist/0b1cc1926bddd31c70ad40663acfec8e to your computer and use it in GitHub Desktop.
Ammonite REPL predef for use with fs2
// 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")
}
@drewboardman
Copy link

I get an error on line 8 occasionally with this predef.

java.lang.NullPointerException
  ammonite.repl.Repl$$anon$1.compiler(Repl.scala:105)
  ammonite.predef.predef$.<clinit>(predef.sc:8)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment