Skip to content

Instantly share code, notes, and snippets.

@fancellu
Created July 17, 2023 15:29
Show Gist options
  • Save fancellu/def2f1564f300234d16249512ee0849b to your computer and use it in GitHub Desktop.
Save fancellu/def2f1564f300234d16249512ee0849b to your computer and use it in GitHub Desktop.
Cats effect 3.x Repl, useful when creating a custom Repl for your Cats effect code
import cats.effect.{IO, IOApp}
// Emits intro text, then prompts for some command. Will exit upon 'exit'
// Note, these programs are values, as expected
object Repl extends IOApp.Simple {
val repl: IO[Unit] = {
for {
input <- IO.println(">>> ") *> IO.readLine
_ <- IO.println(s"You entered: $input") *> (if (input == "exit") IO.unit else repl)
} yield ()
}
override def run: IO[Unit] = for {
_ <- IO.print("Hello, please enter values, and exit loop with 'exit'") *> repl
} yield ()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment