-
Notifications
You must be signed in to change notification settings - Fork 6
Default implicit instance for Console[IO]
#1
Comments
Not sure what's the benefit other than saving two characters Haven't seen many people using |
I think it's needed for final tagless. import cats.effect.IO
import cats.effect.Console
myProgram[IO] and works that way: import cats.effect.IO
import cats.effect.Console
implicit val ConsoleIO = Console.io
myProgram[IO] |
I don't think that's related to final tagless @EnverOsmanov You can get an implicit instance of |
Have you tried running (or compile) |
I don't really know what |
It is from the guide. object App {
import Guide.myProgram
import cats.effect.IO
import cats.effect.Console.io._
def main(args: Array[String]): Unit = {
myProgram[IO].unsafeRunSync()
}
}
object Guide {
import cats.Monad
import cats.effect.Console
import cats.syntax.flatMap._
import cats.syntax.functor._
def myProgram[F[_]: Monad](implicit C: Console[F]): F[Unit] =
for {
_ <- C.putStrLn("Please enter your name: ")
n <- C.readLn
_ <- if (n.nonEmpty) C.putStrLn(s"Hello $n!")
else C.putError("Name is empty!")
} yield ()
} |
That's right. In the guide the program that uses In order to get your program working you need an implicit instance of object App {
import Guide.myProgram
import cats.effect.IO
implicit val consoleIO: Console[IO] = new SyncConsole[IO] // or Console.io'
def main(args: Array[String]): Unit = {
myProgram[IO].unsafeRunSync()
}
} |
Ok. I just thought if there is a default implicit |
Maybe make
Console.io
object implicit?The text was updated successfully, but these errors were encountered: