Console

cats.effect.std.Console
See theConsole companion object
trait Console[F[_]]

Effect type agnostic Console with common methods to write to and read from the standard console. Suited only for extremely simple console input and output.

Attributes

Note:

readLine is not implemented for Scala.js. On Node.js consider using fs2.io.stdin.

Example:
import cats.effect.IO
import cats.effect.std.Console
def myProgram: IO[Unit] =
  for {
    _ <- Console[IO].println("Please enter your name: ")
    n <- Console[IO].readLine
    _ <- if (n.nonEmpty) Console[IO].println("Hello, " + n) else Console[IO].errorln("Name is empty!")
  } yield ()
import cats.Monad
import cats.effect.std.Console
import cats.syntax.all._
def myProgram[F[_]: Console: Monad]: F[Unit] =
  for {
    _ <- Console[F].println("Please enter your name: ")
    n <- Console[F].readLine
    _ <- if (n.nonEmpty) Console[F].println("Hello, " + n) else Console[F].errorln("Name is empty!")
  } yield ()
Companion:
object
Source:
Console.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Concise view

Value members

Abstract methods

def error[A](a: A)(implicit S: Show[A]): F[Unit]
Implicitly added by catsKleisliConsole

Prints a value to the standard error output using the implicit cats.Show instance.

Prints a value to the standard error output using the implicit cats.Show instance.

Attributes

S

implicit cats.Show[A] instance, defaults to cats.Show.fromToString

a

value to be printed to the standard error output

Source:
Console.scala
def error[A](a: A)(implicit S: Show[A]): F[Unit]

Prints a value to the standard error output using the implicit cats.Show instance.

Prints a value to the standard error output using the implicit cats.Show instance.

Attributes

S

implicit cats.Show[A] instance, defaults to cats.Show.fromToString

a

value to be printed to the standard error output

Source:
Console.scala
def errorln[A](a: A)(implicit S: Show[A]): F[Unit]
Implicitly added by catsKleisliConsole

Prints a value to the standard error output followed by a new line using the implicit cast.Show instance.

Prints a value to the standard error output followed by a new line using the implicit cast.Show instance.

Attributes

S

implicit cats.Show[A] instance, defaults to cats.Show.fromToString

a

value to be printed to the standard error output

Source:
Console.scala
def errorln[A](a: A)(implicit S: Show[A]): F[Unit]

Prints a value to the standard error output followed by a new line using the implicit cast.Show instance.

Prints a value to the standard error output followed by a new line using the implicit cast.Show instance.

Attributes

S

implicit cats.Show[A] instance, defaults to cats.Show.fromToString

a

value to be printed to the standard error output

Source:
Console.scala
def println[A](a: A)(implicit S: Show[A]): F[Unit]
Implicitly added by catsKleisliConsole

Prints a value to the standard output followed by a new line using the implicit cats.Show instance.

Prints a value to the standard output followed by a new line using the implicit cats.Show instance.

Attributes

S

implicit cats.Show[A] instance, defaults to cats.Show.fromToString

a

value to be printed to the standard output

Source:
Console.scala
def println[A](a: A)(implicit S: Show[A]): F[Unit]

Prints a value to the standard output followed by a new line using the implicit cats.Show instance.

Prints a value to the standard output followed by a new line using the implicit cats.Show instance.

Attributes

S

implicit cats.Show[A] instance, defaults to cats.Show.fromToString

a

value to be printed to the standard output

Source:
Console.scala

Concrete methods

def mapK[G[_]](f: FunctionK[F, G]): Console[G]
Implicitly added by catsKleisliConsole

Modifies the context in which this console operates using the natural transformation f.

Modifies the context in which this console operates using the natural transformation f.

Attributes

Returns:

a console in the new context obtained by mapping the current one using f

Source:
Console.scala
def mapK[G[_]](f: FunctionK[F, G]): Console[G]

Modifies the context in which this console operates using the natural transformation f.

Modifies the context in which this console operates using the natural transformation f.

Attributes

Returns:

a console in the new context obtained by mapping the current one using f

Source:
Console.scala
Implicitly added by catsKleisliConsole

Prints the stack trace of the given Throwable to standard error output.

Prints the stack trace of the given Throwable to standard error output.

Attributes

Source:
Console.scala

Prints the stack trace of the given Throwable to standard error output.

Prints the stack trace of the given Throwable to standard error output.

Attributes

Source:
Console.scala

Deprecated methods

Implicitly added by catsKleisliConsole

Attributes

Deprecated
true
Source:
Console.scala

Attributes

Deprecated
true
Source:
Console.scala
def readLineWithCharset(charset: Charset): F[String]
Implicitly added by catsKleisliConsole

Attributes

Deprecated
true
Source:
Console.scala
def readLineWithCharset(charset: Charset): F[String]

Attributes

Deprecated
true
Source:
Console.scala