By Alvin Alexander. Last updated: May 6, 2024
Ammonite FAQ: How do I use ZIO 2 in the Ammonite REPL?
Solution
ZIO can be added into the Ammonite REPL as a managed dependency by using Ammonite’s import $ivy
syntax:
import $ivy.`dev.zio::zio:2.0.22`
To really use ZIO in the Ammonite REPL, you’ll probably want to use both of these import
statements:
import $ivy.`dev.zio::zio:2.0.22`
import $ivy.`fr.janalyse::zio-worksheet:2.0.12.0`
The first one imports the ZIO library, and the second one imports the ZIO Worksheet library, which lets you easily run ZIO applications in a REPL environment, as shown in their example, which I have converted to the Ammonite REPL syntax:
import $ivy.`dev.zio::zio:2.0.22`
import $ivy.`fr.janalyse::zio-worksheet:2.0.12.0`
import zio.*
import zio.worksheet.*
val app = Console.printLine("Hello world !")
app.unsafeRun
In summary, if you wanted to see how to use ZIO in the Ammonite REPL, I hope these examples are helpful.