trait Console[F[_]] extends ConsoleCrossPlatform[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 in trivial applications.
- Source
- Console.scala
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 ()
- Alphabetic
- By Inheritance
- Console
- ConsoleCrossPlatform
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
- abstract def error[A](a: A)(implicit S: Show[A] = Show.fromToString[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.- a
value to be printed to the standard error output
- S
implicit
cats.Show[A]
instance, defaults tocats.Show.fromToString
- Definition Classes
- Console → ConsoleCrossPlatform
- abstract def errorln[A](a: A)(implicit S: Show[A] = Show.fromToString[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.- a
value to be printed to the standard error output
- S
implicit
cats.Show[A]
instance, defaults tocats.Show.fromToString
- Definition Classes
- Console → ConsoleCrossPlatform
- abstract def print[A](a: A)(implicit S: Show[A] = Show.fromToString[A]): F[Unit]
Prints a value to the standard output using the implicit
cats.Show
instance.Prints a value to the standard output using the implicit
cats.Show
instance.- a
value to be printed to the standard output
- S
implicit
cats.Show[A]
instance, defaults tocats.Show.fromToString
- Definition Classes
- Console → ConsoleCrossPlatform
- abstract def println[A](a: A)(implicit S: Show[A] = Show.fromToString[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.- a
value to be printed to the standard output
- S
implicit
cats.Show[A]
instance, defaults tocats.Show.fromToString
- Definition Classes
- Console → ConsoleCrossPlatform
- abstract 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 finitejava.io.InputStream
throughjava.lang.System#setIn
or similar.- 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 Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def mapK[G[_]](f: ~>[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
- Definition Classes
- Console → ConsoleCrossPlatform
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- 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.
- Definition Classes
- Console → ConsoleCrossPlatform
- 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 finitejava.io.InputStream
throughjava.lang.System#setIn
or similar.- returns
an effect that describes reading the user's input from the standard input as a string
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()