Skip to content

Instantly share code, notes, and snippets.

@fancellu
Created July 17, 2023 15:29
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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