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. Due to issues around cancellation in readLine, suited only for extremely simple console input and output in trivial applications.

Attributes

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
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.

Attributes

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

Source:
Console.scala
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.

Attributes

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

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
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.

Attributes

Returns:

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

Source:
Console.scala

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.

Attributes

Returns:

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

Source:
Console.scala