Trait/Object

cats.effect

Console

Related Docs: object Console | package effect

Permalink

trait Console[F[_]] extends ConsoleIn[F] with ConsoleOut[F] with ConsoleError[F]

Effect type agnostic Console with common methods to write and read from the standard console.

For an implementation that uses standard input/output, see Console.io (for Console[IO]) or SyncConsole.stdio (for any F[_]: Sync).

Use it either in a DSL style:

import cats.effect.IO
import cats.effect.Console.io._

val program: IO[Unit] =
  for {
    _ <- putStrLn("Please enter your name: ")
    n <- readLn
    _ <- if (n.nonEmpty) putStrLn(s"Hello $$n!")
         else putError("Name is empty!")
  } yield ()

Or in Tagless Final encoding:

import cats.Monad
import cats.effect._

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 ()
Self Type
Console[F]
Linear Supertypes
ConsoleError[F], ConsoleOut[F], ConsoleIn[F], AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Console
  2. ConsoleError
  3. ConsoleOut
  4. ConsoleIn
  5. AnyRef
  6. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def putError[A](a: A)(implicit arg0: Show[A]): F[Unit]

    Permalink

    Prints a message of type A followed by a new line to the error output using the implicit Show[A] instance.

    Prints a message of type A followed by a new line to the error output using the implicit Show[A] instance.

    Definition Classes
    ConsoleError
  2. abstract def putStr[A](a: A)(implicit arg0: Show[A]): F[Unit]

    Permalink

    Prints a message of type A to the console using the implicit Show[A] instance.

    Prints a message of type A to the console using the implicit Show[A] instance.

    Definition Classes
    ConsoleOut
  3. abstract def putStrLn[A](a: A)(implicit arg0: Show[A]): F[Unit]

    Permalink

    Prints a message of type A followed by a new line to the console using the implicit Show[A] instance.

    Prints a message of type A followed by a new line to the console using the implicit Show[A] instance.

    Definition Classes
    ConsoleOut
  4. abstract def readLn: F[String]

    Permalink

    Reads a line from the console input.

    Reads a line from the console input.

    returns

    a value representing the user's input.

    Definition Classes
    ConsoleIn

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  9. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  10. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  11. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  12. def mapK[G[_]](fk: ~>[F, G]): Console[G]

    Permalink

    Transforms this console using a FunctionK.

    Transforms this console using a FunctionK.

    Definition Classes
    ConsoleConsoleErrorConsoleOutConsoleIn
  13. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  14. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  15. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  16. def putError(str: String): F[Unit]

    Permalink

    Prints a message to the error output.

    Prints a message to the error output.

    Definition Classes
    ConsoleError
  17. def putStr(str: String): F[Unit]

    Permalink

    Prints a message to the console.

    Prints a message to the console.

    Definition Classes
    ConsoleOut
  18. def putStrLn(str: String): F[Unit]

    Permalink

    Prints a message to the console followed by a new line.

    Prints a message to the console followed by a new line.

    Definition Classes
    ConsoleOut
  19. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  20. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  21. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  22. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  23. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from ConsoleError[F]

Inherited from ConsoleOut[F]

Inherited from ConsoleIn[F]

Inherited from AnyRef

Inherited from Any

Ungrouped