package zio
- Alphabetic
- By Inheritance
- zio
- EitherCompat
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
trait
App extends DefaultRuntime
The entry point for a purely-functional application on the JVM.
The entry point for a purely-functional application on the JVM.
import scalaz.zio.App import scalaz.zio.console._ object MyApp extends App { final def run(args: List[String]) = myAppLogic.attempt.map(_.fold(_ => 1, _ => 0)) def myAppLogic = for { _ <- putStrLn("Hello! What is your name?") n <- getStrLn _ <- putStrLn("Hello, " + n + ", good to meet you!") } yield () }
- type Canceler = UIO[_]
-
sealed
trait
Chunk[+A] extends AnyRef
A
Chunk[A]represents a chunk of values of typeA.A
Chunk[A]represents a chunk of values of typeA. Chunks are designed are usually backed by arrays, but expose a purely functional, safe interface to the underlying elements, and they become lazy on operations that would be costly with arrays, such as repeated concatenation. - trait DefaultRuntime extends Runtime[Clock with Console with System with Random with Blocking]
- trait EitherCompat extends AnyRef
-
sealed
trait
Exit[+E, +A] extends Product with Serializable
An
Exit[E, A]describes the result of executing anIOvalue.An
Exit[E, A]describes the result of executing anIOvalue. The result is either succeeded with a valueA, or failed with aCause[E]. -
trait
Fiber[+E, +A] extends AnyRef
A fiber is a lightweight thread of execution that never consumes more than a whole thread (but may consume much less, depending on contention).
A fiber is a lightweight thread of execution that never consumes more than a whole thread (but may consume much less, depending on contention). Fibers are spawned by forking
IOactions, which, conceptually at least, runs them concurrently with the parentIOaction.Fibers can be joined, yielding their result other fibers, or interrupted, which terminates the fiber with a runtime error.
Fork-Join Identity: fork >=> join = id
for { fiber1 <- io1.fork fiber2 <- io2.fork _ <- fiber1.interrupt(e) a <- fiber2.join } yield a
-
final
case class
FiberFailure(cause: Cause[Any]) extends Throwable with Product with Serializable
Represents a failure in a fiber.
Represents a failure in a fiber. This could be caused by some non- recoverable error, such as a defect or system error, by some typed error, or by interruption (or combinations of all of the above).
This class is used to wrap ZIO failures into something that can be thrown, to better integrate with Scala exception handling.
- type FiberId = Long
-
final
class
FiberLocal[A] extends Serializable
A container for fiber-local storage.
A container for fiber-local storage. It is the pure equivalent to Java's
ThreadLocalon a fiber architecture. -
sealed
trait
FunctionIO[+E, -A, +B] extends Serializable
A
FunctionIO[E, A, B]is an effectful function fromAtoB, which might fail with anE.A
FunctionIO[E, A, B]is an effectful function fromAtoB, which might fail with anE.This is the moral equivalent of
A => IO[E, B], and, indeed,FunctionIOextends this function type, and can be used in the same way.The main advantage to using
FunctionIOis that it provides you a means of importing an impure functionA => BintoFunctionIO[E, A, B], without actually wrapping the result of the function in anIOvalue.This allows the implementation to aggressively fuse operations on impure functions, which in turn can result in significantly higher-performance and far less heap utilization than equivalent approaches modeled with
IO.The implementation allows you to lift functions from
A => IO[E, B]into aFunctionIO[E, A, B]. Such functions cannot be optimized, but will be handled correctly and can work in conjunction with optimized (fused)FunctionIO.Those interested in learning more about modeling effects with
FunctionIOare encouraged to read John Hughes paper on the subject: Generalizing Monads to Arrows (www.cse.chalmers.se/~rjmh/Papers/arrows.pdf). The implementation in this file contains many of the same combinators as Hughes implementation.A word of warning: while even very complex code can be expressed in
FunctionIO, there is a point of diminishing return. If you find yourself using deeply nested tuples to propagate information forward, it may be no faster than usingIO.Given the following two
FunctionIO:val readLine = FunctionIO.impureVoid((_ : Unit) => scala.Console.readLine()) val printLine = FunctionIO.impureVoid((line: String) => println(line))
Then the following two programs are equivalent:
// Program 1 val program1: UIO[Unit] = for { name <- getStrLn _ <- putStrLn("Hello, " + name) } yield ()) // Program 2 val program2: UIO[Unit] = (readLine >>> FunctionIO.fromFunction("Hello, " + _) >>> printLine)(())
Similarly, the following two programs are equivalent:
// Program 1 val program1: UIO[Unit] = for { line1 <- getStrLn line2 <- getStrLn _ <- putStrLn("You wrote: " + line1 + ", " + line2) } yield ()) // Program 2 val program2: UIO[Unit] = (readLine.zipWith(readLine)("You wrote: " + _ + ", " + _) >>> printLine)(())
In both of these examples, the
FunctionIOprogram is faster because it is able to perform fusion of effectful functions. - type IO[+E, +A] = ZIO[Any, E, A]
- type Managed[+E, +A] = ZManaged[Any, E, A]
-
final
class
Promise[E, A] extends AnyVal
A promise represents an asynchronous variable that can be set exactly once, with the ability for an arbitrary number of fibers to suspend (by calling
get) and automatically resume when the variable is set.A promise represents an asynchronous variable that can be set exactly once, with the ability for an arbitrary number of fibers to suspend (by calling
get) and automatically resume when the variable is set.Promises can be used for building primitive actions whose completions require the coordinated action of multiple fibers, and for building higher-level concurrent or asynchronous structures.
for { promise <- Promise.make[Nothing, Int] _ <- promise.complete(42).delay(1.second).fork value <- promise.get // Resumes when forked fiber completes promise } yield value
- type Queue[A] = Queue2[Any, Nothing, Any, Nothing, A, A]
-
trait
Queue2[-RA, +EA, -RB, +EB, -A, +B] extends Serializable
A
Queue2[RA, EA, RB, EB, A, B]is a lightweight, asynchronous queue into which values of typeAcan be enqueued and of which elements of typeBcan be dequeued.A
Queue2[RA, EA, RB, EB, A, B]is a lightweight, asynchronous queue into which values of typeAcan be enqueued and of which elements of typeBcan be dequeued. The queue's enqueueing operations may utilize an environment of typeRAand may fail with errors of typeEA. The dequeueing operations may utilize an environment of typeRBand may fail with errors of typeEB. -
final
class
Ref[A] extends AnyVal with Serializable
A mutable atomic reference for the
IOmonad.A mutable atomic reference for the
IOmonad. This is theIOequivalent of a volatilevar, augmented with atomic operations, which make it useful as a reasonably efficient (if low-level) concurrency primitive.for { ref <- Ref.make(2) v <- ref.update(_ + 3) _ <- console.putStrLn("Value = " + v) // Value = 5 } yield ()
-
final
class
RefM[A] extends Serializable
A mutable atomic reference for the
IOmonad.A mutable atomic reference for the
IOmonad. This is theIOequivalent of a volatilevar, augmented with atomic effectful operations, which make it useful as a reasonably efficient (if low-level) concurrency primitive.Unlike
Ref,RefMallows effects in atomic operations, which makes the structure slower but more powerful thanRef.for { ref <- RefM(2) v <- ref.update(_ + putStrLn("Hello World!").attempt.void *> IO.succeed(3)) _ <- putStrLn("Value = " + v) // Value = 5 } yield ()
-
trait
Runtime[+R] extends AnyRef
A
Runtime[R]is capable of executing tasks within an environmentR. - type Schedule[-A, +B] = ZSchedule[Any, A, B]
- trait Schedule_Functions extends Serializable
-
final
class
Semaphore extends Serializable
An asynchronous semaphore, which is a generalization of a mutex.
An asynchronous semaphore, which is a generalization of a mutex. Semaphores have a certain number of permits, which can be held and released concurrently by different parties. Attempts to acquire more permits than available result in the acquiring fiber being suspended until the specified number of permits become available.
- type Task[+A] = ZIO[Any, Throwable, A]
- type TaskR[-R, +A] = ZIO[R, Throwable, A]
- type UIO[+A] = ZIO[Any, Nothing, A]
-
sealed
trait
ZIO[-R, +E, +A] extends Serializable
A
ZIO[R, E, A]("Zee-Oh of Are Eeh Aye") is an immutable data structure that models an effectful program.A
ZIO[R, E, A]("Zee-Oh of Are Eeh Aye") is an immutable data structure that models an effectful program. The program requires an environmentR, and the program may fail with an errorEor produce a singleA.Conceptually, this structure is equivalent to
ReaderT[R, EitherT[UIO, E, ?]]for some infallible effect monadUIO, but because monad transformers perform poorly in Scala, this data structure bakes in the reader effect ofReaderTwith the recoverable error effect ofEitherTwithout runtime overhead.ZIOvalues are ordinary immutable values, and may be used like any other value in purely functional code. BecauseZIOvalues just *model* effects (like input / output), which must be interpreted by a separate runtime system,ZIOvalues are entirely pure and do not violate referential transparency.ZIOvalues can efficiently describe the following classes of effects:- Pure Values —
ZIO.succeed —Error EffectsZIO.fail- Synchronous Effects —
IO.effect - Asynchronous Effects —
IO.effectAsync - Concurrent Effects —
IO#fork - Resource Effects —
IO#bracket —Contextual EffectsZIO.access
The concurrency model is based on fibers, a user-land lightweight thread, which permit cooperative multitasking, fine-grained interruption, and very high performance with large numbers of concurrently executing fibers.
ZIOvalues compose with otherZIOvalues in a variety of ways to build complex, rich, interactive applications. See the methods onZIOfor more details about how to composeZIOvalues.In order to integrate with Scala,
ZIOvalues must be interpreted into the Scala runtime. This process of interpretation executes the effects described by a given immutableZIOvalue. For more information on interpretingZIOvalues, see the default interpreter inDefaultRuntimeor the safe main function inApp. - Pure Values —
- trait ZIOFunctions extends Serializable
- trait ZIO_E_Any extends ZIO_E_Throwable
- trait ZIO_E_Throwable extends ZIOFunctions
- trait ZIO_R_Any extends ZIO_E_Any
-
final
case class
ZManaged[-R, +E, +A](reserve: ZIO[R, E, Reservation[R, E, A]]) extends Product with Serializable
A
ZManaged[R, E, A]is a managed resource of typeA, which may be used by invoking theusemethod of the resource.A
ZManaged[R, E, A]is a managed resource of typeA, which may be used by invoking theusemethod of the resource. The resource will be automatically acquired before the resource is used, and automatically released after the resource is used.Resources do not survive the scope of
use, meaning that if you attempt to capture the resource, leak it fromuse, and then use it after the resource has been consumed, the resource will not be valid anymore and may fail with some checked error, as per the type of the functions provided by the resource. -
trait
ZSchedule[-R, -A, +B] extends Serializable
Defines a stateful, possibly effectful, recurring schedule of actions.
Defines a stateful, possibly effectful, recurring schedule of actions.
A
ZSchedule[R, A, B]consumesAvalues, and based on the inputs and the internal state, decides whether to continue or halt. Every decision is accompanied by a (possibly zero) delay, and an output value of typeB.Schedules compose in each of the following ways:
1. Intersection, using the
&&operator, which requires that both schedules continue, using the longer of the two durations. 2. Union, using the||operator, which requires that only one schedule continues, using the shorter of the two durations. 3. Sequence, using the<||>operator, which runs the first schedule until it ends, and then switches over to the second schedule.Schedule[R, A, B]forms a profunctor on[A, B], an applicative functor onB, and a monoid, allowing rich composition of different schedules.
Value Members
- val JustExceptions: PartialFunction[Throwable, Exception]
- val Managed: ZManaged.type
- val Queue: Queue2.type
-
object
BuildInfo extends Product with Serializable
This object was generated by sbt-buildinfo.
- object Chunk
- object Exit extends Serializable
- object Fiber
- object FiberLocal extends Serializable
- object FunctionIO extends Serializable
- object IO extends ZIO_E_Any
- object Promise
- object Queue2 extends Serializable
- object Ref extends Serializable
- object RefM extends Serializable
- object Runtime
- object Schedule extends Schedule_Functions
- object Semaphore extends Serializable
- object Task extends ZIO_E_Throwable
- object TaskR extends ZIO_E_Throwable
- object UIO extends ZIOFunctions
- object ZIO extends ZIO_R_Any
- object ZManaged extends Serializable
- object ZSchedule extends Schedule_Functions