Console

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.

Example
 import cats.effect.std.Console
 import cats.effect.kernel.Sync
 import cats.syntax.all._
 implicit val console = Console.sync[F]
 def myProgram[F[_]: Console]: 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
class Object
trait Matchable
class Any

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.

Value Params
S

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

a

value to be printed to the standard error output

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.

Value Params
S

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

a

value to be printed to the standard error output

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.

Value Params
S

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

a

value to be printed to the standard error output

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.

Value Params
S

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

a

value to be printed to the standard error output

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.

Value Params
S

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

a

value to be printed to the standard output

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.

Value Params
S

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

a

value to be printed to the standard output

def readLineWithCharset(charset: Charset): F[String]
Implicitly added by catsKleisliConsole

Reads a line as a string from the standard input using the provided charset.

Reads a line as a string from the standard input using the provided charset.

The effect can raise a java.io.EOFException if no input has been consumed before the EOF is observed. This should never happen with the standard input, unless it has been replaced with a finite java.io.InputStream through java.lang.System#setIn or similar.

Value Params
charset

the java.nio.charset.Charset to be used when decoding the input stream

Returns

an effect that describes reading the user's input from the standard input as a string

def readLineWithCharset(charset: Charset): F[String]

Reads a line as a string from the standard input using the provided charset.

Reads a line as a string from the standard input using the provided charset.

The effect can raise a java.io.EOFException if no input has been consumed before the EOF is observed. This should never happen with the standard input, unless it has been replaced with a finite java.io.InputStream through java.lang.System#setIn or similar.

Value Params
charset

the java.nio.charset.Charset to be used when decoding the input stream

Returns

an effect that describes reading the user's input from the standard input as a string

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.

Returns

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

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.

Returns

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

def printStackTrace(t: Throwable): F[Unit]
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.

def printStackTrace(t: Throwable): F[Unit]

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

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

def readLine: F[String]
Implicitly added by catsKleisliConsole

Reads a line as a string from the standard input using the platform's default charset, as per java.nio.charset.Charset.defaultCharset().

Reads a line as a string from the standard input using the platform's default charset, as per java.nio.charset.Charset.defaultCharset().

The effect can raise a java.io.EOFException if no input has been consumed before the EOF is observed. This should never happen with the standard input, unless it has been replaced with a finite java.io.InputStream through java.lang.System#setIn or similar.

Returns

an effect that describes reading the user's input from the standard input as a string

def readLine: F[String]

Reads a line as a string from the standard input using the platform's default charset, as per java.nio.charset.Charset.defaultCharset().

Reads a line as a string from the standard input using the platform's default charset, as per java.nio.charset.Charset.defaultCharset().

The effect can raise a java.io.EOFException if no input has been consumed before the EOF is observed. This should never happen with the standard input, unless it has been replaced with a finite java.io.InputStream through java.lang.System#setIn or similar.

Returns

an effect that describes reading the user's input from the standard input as a string