Cats effect 3.x Repl, useful when creating a custom Repl for your Cats effect code
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
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