Packages

object IO extends IOCompanionPlatform with IOLowPriorityImplicits

Source
IO.scala
Linear Supertypes
IOLowPriorityImplicits, IOCompanionPlatform, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. IO
  2. IOLowPriorityImplicits
  3. IOCompanionPlatform
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. class IOMonoid[A] extends IOSemigroup[A] with Monoid[IO[A]]
    Attributes
    protected
  2. class IOSemigroup[A] extends Semigroup[IO[A]]
    Attributes
    protected
    Definition Classes
    IOLowPriorityImplicits
  3. class IOSemigroupK extends SemigroupK[IO]
    Attributes
    protected
  4. type Par[A] = T[IO, A]

    Newtype encoding for an IO datatype that has a cats.Applicative capable of doing parallel processing in ap and map2, needed for implementing cats.Parallel.

    Newtype encoding for an IO datatype that has a cats.Applicative capable of doing parallel processing in ap and map2, needed for implementing cats.Parallel.

    Helpers are provided for converting back and forth in Par.apply for wrapping any IO value and Par.unwrap for unwrapping.

    The encoding is based on the "newtypes" project by Alexander Konovalov, chosen because it's devoid of boxing issues and a good choice until opaque types will land in Scala.

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. implicit def alignForIO: Align[IO]
  5. def apply[A](thunk: ⇒ A): IO[A]

    Suspends a synchronous side effect in IO.

    Suspends a synchronous side effect in IO.

    Alias for IO.delay(body).

  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. def async[A](k: ((Either[Throwable, A]) ⇒ Unit) ⇒ IO[Option[IO[Unit]]]): IO[A]
  8. implicit def asyncForIO: kernel.Async[IO]
  9. def async_[A](k: ((Either[Throwable, A]) ⇒ Unit) ⇒ Unit): IO[A]

    Suspends an asynchronous side effect in IO.

    Suspends an asynchronous side effect in IO.

    The given function will be invoked during evaluation of the IO to "schedule" the asynchronous callback, where the callback is the parameter passed to that function. Only the first invocation of the callback will be effective! All subsequent invocations will be silently dropped.

    As a quick example, you can use this function to perform a parallel computation given an ExecutorService:

    def fork[A](body: => A, exc: ExecutorService): IO[A] =
      IO async_ { cb =>
        exc.execute(new Runnable {
          def run() =
            try cb(Right(body)) catch { case NonFatal(t) => cb(Left(t)) }
        })
      }

    The fork function will do exactly what it sounds like: take a thunk and an ExecutorService and run that thunk on the thread pool. Or rather, it will produce an IO which will do those things when run; it does *not* schedule the thunk until the resulting IO is run! Note that there is no thread blocking in this implementation; the resulting IO encapsulates the callback in a pure and monadic fashion without using threads.

    This function can be thought of as a safer, lexically-constrained version of Promise, where IO is like a safer, lazy version of Future.

    See also

    async

  10. def blocking[A](thunk: ⇒ A): IO[A]
    Definition Classes
    IOCompanionPlatform
  11. def both[A, B](left: IO[A], right: IO[B]): IO[(A, B)]
  12. def bothOutcome[A, B](left: IO[A], right: IO[B]): IO[(OutcomeIO[A], OutcomeIO[B])]
  13. def bracketFull[A, B](acquire: (Poll[IO]) ⇒ IO[A])(use: (A) ⇒ IO[B])(release: (A, OutcomeIO[B]) ⇒ IO[Unit]): IO[B]
  14. def canceled: IO[Unit]
  15. def cede: IO[Unit]
  16. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  17. implicit val consoleForIO: Console[IO]
  18. def cont[K, R](body: Cont[IO, K, R]): IO[R]

    This is a low-level API which is meant for implementors, please use background, start, async, or Deferred instead, depending on the use case

  19. def defer[A](thunk: ⇒ IO[A]): IO[A]

    Suspends a synchronous side effect which produces an IO in IO.

    Suspends a synchronous side effect which produces an IO in IO.

    This is useful for trampolining (i.e. when the side effect is conceptually the allocation of a stack frame). Any exceptions thrown by the side effect will be caught and sequenced into the IO.

  20. def deferred[A]: IO[Deferred[IO, A]]
  21. def delay[A](thunk: ⇒ A): IO[A]

    Suspends a synchronous side effect in IO.

    Suspends a synchronous side effect in IO.

    Any exceptions thrown by the effect will be caught and sequenced into the IO.

  22. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  23. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  24. def eval[A](fa: Eval[A]): IO[A]

    Lifts an Eval into IO.

    Lifts an Eval into IO.

    This function will preserve the evaluation semantics of any actions that are lifted into the pure IO. Eager Eval instances will be converted into thunk-less IO (i.e. eager IO), while lazy eval and memoized will be executed as such.

  25. def executionContext: IO[ExecutionContext]
  26. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  27. def fromCompletableFuture[A](fut: IO[CompletableFuture[A]]): IO[A]
    Definition Classes
    IOCompanionPlatform
  28. def fromEither[A](e: Either[Throwable, A]): IO[A]

    Lifts an Either[Throwable, A] into the IO[A] context, raising the throwable if it exists.

  29. def fromFuture[A](fut: IO[Future[A]]): IO[A]

    Constructs an IO which evaluates the given Future and produces the result (or failure).

    Constructs an IO which evaluates the given Future and produces the result (or failure).

    Because Future eagerly evaluates, as well as because it memoizes, this function takes its parameter as an IO, which could be lazily evaluated. If this laziness is appropriately threaded back to the definition site of the Future, it ensures that the computation is fully managed by IO and thus referentially transparent.

    Example:

    // Lazy evaluation, equivalent with by-name params
    IO.fromFuture(IO(f))
    
    // Eager evaluation, for pure futures
    IO.fromFuture(IO.pure(f))

    Roughly speaking, the following identities hold:

    IO.fromFuture(IO(f)).unsafeToFuture() === f // true-ish (except for memoization)
    IO.fromFuture(IO(ioa.unsafeToFuture())) === ioa // true
    See also

    IO#unsafeToFuture

  30. def fromOption[A](o: Option[A])(orElse: ⇒ Throwable): IO[A]

    Lifts an Option[A] into the IO[A] context, raising the throwable if the option is empty.

  31. def fromTry[A](t: Try[A]): IO[A]

    Lifts an Try[A] into the IO[A] context, raising the throwable if it exists.

  32. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  33. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  34. def interruptible[A](many: Boolean)(thunk: ⇒ A): IO[A]
    Definition Classes
    IOCompanionPlatform
  35. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  36. implicit def monoidForIO[A](implicit arg0: Monoid[A]): Monoid[IO[A]]
  37. def monotonic: IO[FiniteDuration]
  38. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  39. def never[A]: IO[A]

    A non-terminating IO, alias for async(_ => ()).

  40. def none[A]: IO[Option[A]]

    An IO that contains an empty Option.

    An IO that contains an empty Option.

    See also

    some for the non-empty Option variant

  41. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  42. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  43. def parSequenceN[T[_], A](n: Int)(tma: T[IO[A]])(implicit arg0: Traverse[T]): IO[T[A]]

    Like Parallel.parSequence, but limits the degree of parallelism.

  44. def parTraverseN[T[_], A, B](n: Int)(ta: T[A])(f: (A) ⇒ IO[B])(implicit arg0: Traverse[T]): IO[T[B]]

    Like Parallel.parTraverse, but limits the degree of parallelism.

  45. implicit def parallelForIO: Aux[IO, Par]
  46. def print[A](a: A)(implicit S: Show[A] = Show.fromToString[A]): IO[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

    See also

    cats.effect.std.Console for more standard input, output and error operations

  47. def println[A](a: A)(implicit S: Show[A] = Show.fromToString[A]): IO[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

    See also

    cats.effect.std.Console for more standard input, output and error operations

  48. def pure[A](value: A): IO[A]

    Lifts a pure value into IO.

    Lifts a pure value into IO.

    This should only be used if the value in question has "already" been computed! In other words, something like IO.pure(readLine) is most definitely not the right thing to do! However, IO.pure(42) is correct and will be more efficient (when evaluated) than IO(42), due to avoiding the allocation of extra thunks.

  49. def race[A, B](left: IO[A], right: IO[B]): IO[Either[A, B]]

    Run two IO tasks concurrently, and return the first to finish, either in success or error.

    Run two IO tasks concurrently, and return the first to finish, either in success or error. The loser of the race is canceled.

    The two tasks are executed in parallel, the winner being the first that signals a result.

    As an example see IO.timeout and IO.timeoutTo

    Also see racePair for a version that does not cancel the loser automatically on successful results.

  50. def racePair[A, B](left: IO[A], right: IO[B]): IO[Either[(OutcomeIO[A], FiberIO[B]), (FiberIO[A], OutcomeIO[B])]]

    Run two IO tasks concurrently, and returns a pair containing both the winner's successful value and the loser represented as a still-unfinished task.

    Run two IO tasks concurrently, and returns a pair containing both the winner's successful value and the loser represented as a still-unfinished task.

    If the first task completes in error, then the result will complete in error, the other task being canceled.

    On usage the user has the option of canceling the losing task, this being equivalent with plain race:

    val ioA: IO[A] = ???
    val ioB: IO[B] = ???
    
    IO.racePair(ioA, ioB).flatMap {
      case Left((a, fiberB)) =>
        fiberB.cancel.map(_ => a)
      case Right((fiberA, b)) =>
        fiberA.cancel.map(_ => b)
    }

    See race for a simpler version that cancels the loser immediately.

  51. def raiseError[A](t: Throwable): IO[A]

    Constructs an IO which sequences the specified exception.

    Constructs an IO which sequences the specified exception.

    If this IO is run using unsafeRunSync or unsafeRunTimed, the exception will be thrown. This exception can be "caught" (or rather, materialized into value-space) using the attempt method.

    See also

    IO#attempt

  52. def raiseUnless(cond: Boolean)(e: ⇒ Throwable): IO[Unit]

    Returns raiseError when cond is false, otherwise IO.unit

    Returns raiseError when cond is false, otherwise IO.unit

    Example:
    1. val tooMany = 5
      val x: Int = ???
      IO.raiseUnless(x < tooMany)(new IllegalArgumentException("Too many"))
  53. def raiseWhen(cond: Boolean)(e: ⇒ Throwable): IO[Unit]

    Returns raiseError when the cond is true, otherwise IO.unit

    Returns raiseError when the cond is true, otherwise IO.unit

    Example:
    1. val tooMany = 5
      val x: Int = ???
      IO.raiseWhen(x >= tooMany)(new IllegalArgumentException("Too many"))
  54. def readLine: IO[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 IO effect that describes reading the user's input from the standard input as a string

    See also

    cats.effect.std.Console#readLineWithCharset for reading using a custom java.nio.charset.Charset

  55. def realTime: IO[FiniteDuration]
  56. def realTimeInstant: IO[Instant]
    Definition Classes
    IOCompanionPlatform
  57. def ref[A](a: A): IO[Ref[IO, A]]
  58. implicit def semigroupForIO[A](implicit arg0: Semigroup[A]): Semigroup[IO[A]]
    Definition Classes
    IOLowPriorityImplicits
  59. implicit val semigroupKForIO: SemigroupK[IO]
  60. implicit def showForIO[A](implicit arg0: Show[A]): Show[IO[A]]
  61. implicit def showForIONoPure[A]: Show[IO[A]]
    Definition Classes
    IOLowPriorityImplicits
  62. def sleep(delay: FiniteDuration): IO[Unit]

    Creates an asynchronous task that on evaluation sleeps for the specified duration, emitting a notification on completion.

    Creates an asynchronous task that on evaluation sleeps for the specified duration, emitting a notification on completion.

    This is the pure, non-blocking equivalent to:

    • Thread.sleep (JVM)
    • ScheduledExecutorService.schedule (JVM)
    • setTimeout (JavaScript)

    You can combine it with flatMap to create delayed tasks:

    val timeout = IO.sleep(10.seconds).flatMap { _ =>
      IO.raiseError(new TimeoutException)
    }

    The created task is cancelable and so it can be used safely in race conditions without resource leakage.

    returns

    a new asynchronous and cancelable IO that will sleep for the specified duration and then finally emit a tick

  63. def some[A](a: A): IO[Option[A]]

    An IO that contains some Option of the given value.

    An IO that contains some Option of the given value.

    See also

    none for the empty Option variant

  64. def stub: IO[Nothing]
  65. def suspend[A](hint: Type)(thunk: ⇒ A): IO[A]
    Definition Classes
    IOCompanionPlatform
  66. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  67. def toString(): String
    Definition Classes
    AnyRef → Any
  68. def trace: IO[Trace]
  69. def uncancelable[A](body: (Poll[IO]) ⇒ IO[A]): IO[A]
  70. def unique: IO[Token]
  71. def unit: IO[Unit]

    Alias for IO.pure(()).

  72. def unlessA(cond: Boolean)(action: ⇒ IO[Unit]): IO[Unit]

    Returns the given argument if cond is false, otherwise IO.Unit

    Returns the given argument if cond is false, otherwise IO.Unit

    See also

    IO.whenA for the inverse

    IO.raiseWhen for conditionally raising an error

  73. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  74. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  75. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  76. def whenA(cond: Boolean)(action: ⇒ IO[Unit]): IO[Unit]

    Returns the given argument if cond is true, otherwise IO.Unit

    Returns the given argument if cond is true, otherwise IO.Unit

    See also

    IO.unlessA for the inverse

    IO.raiseWhen for conditionally raising an error

Inherited from IOLowPriorityImplicits

Inherited from IOCompanionPlatform

Inherited from AnyRef

Inherited from Any

Ungrouped