Introduction
ZIO contains a few data types that can help you solve complex problems in asynchronous and concurrent programming. ZIO data types categorize into these sections:
Core Data Types​
- ZIO — A
ZIO
is a value that models an effectful program, which might fail or succeed.- UIO — An
UIO[A]
is a type alias forZIO[Any, Nothing, A]
. - URIO — An
URIO[R, A]
is a type alias forZIO[R, Nothing, A]
. - Task — A
Task[A]
is a type alias forZIO[Any, Throwable, A]
. - RIO — A
RIO[R, A]
is a type alias forZIO[R, Throwable, A]
. - IO — An
IO[E, A]
is a type alias forZIO[Any, E, A]
.
- UIO — An
- Exit — An
Exit[E, A]
describes the result of executing anIO
value. - Cause -
Cause[E]
is a description of a full story of a fiber failure. - Runtime — A
Runtime[R]
is capable of executing tasks within an environmentR
.
Contextual Data Types​
- Has — The trait
Has[A]
is used with the ZIO environment to express an effect's dependency on a service of typeA
. - ZLayer — The
ZIO[-R, +E, +A]
data type describes an effect that requires an input type ofR
, as an environment, may fail with an error of typeE
or succeed and produces a value of typeA
.- RLayer —
RLayer[-RIn, +ROut]
is a type alias forZLayer[RIn, Throwable, ROut]
, which represents a layer that requiresRIn
as its input, it may fail withThrowable
value, or returnsROut
as its output. - ULayer — ULayer[+ROut] is a type alias for ZLayer[Any, Nothing, ROut], which represents a layer that doesn't require any services as its input, it can't fail, and returns ROut as its output.
- Layer — Layer[+E, +ROut] is a type alias for ZLayer[Any, E, ROut], which represents a layer that doesn't require any services, it may fail with an error type of E, and returns ROut as its output.
- URLayer — URLayer[-RIn, +ROut] is a type alias for ZLayer[RIn, Nothing, ROut], which represents a layer that requires RIn as its input, it can't fail, and returns ROut as its output.
- TaskLayer — TaskLayer[+ROut] is a type alias for ZLayer[Any, Throwable, ROut], which represents a layer that doesn't require any services as its input, it may fail with Throwable value, and returns ROut as its output.
- RLayer —
Concurrency​
Fiber Primitives​
- Fiber — A fiber value models an
IO
value that has started running, and is the moral equivalent of a green thread. - FiberRef —
FiberRef[A]
models a mutable reference to a value of typeA
. As opposed toRef[A]
, a value is bound to an executingFiber
only. You can think of it as Java'sThreadLocal
on steroids. - Fiber.Status —
Fiber.Status
describe the current status of a Fiber. - Fiber.Id —
Fiber.Id
describe the unique identity of a Fiber.
Concurrency Primitives​
- Hub - A
Hub
is an asynchronous message hub that allows publishers to efficiently broadcast values to many subscribers. - Promise — A
Promise
is a model of a variable that may be set a single time, and awaited on by many fibers. - Semaphore — A
Semaphore
is an asynchronous (non-blocking) semaphore that plays well with ZIO's interruption. - ZRef — A
ZRef[EA, EB, A, B]
is a polymorphic, purely functional description of a mutable reference. The fundamental operations of aZRef
areset
andget
.- Ref —
Ref[A]
models a mutable reference to a value of typeA
. The two basic operations areset
, which fills theRef
with a new value, andget
, which retrieves its current content. All operations on aRef
are atomic and thread-safe, providing a reliable foundation for synchronizing concurrent programs.
- Ref —
- ZRefM — A
ZRefM[RA, RB, EA, EB, A, B]
is a polymorphic, purely functional description of a mutable reference.- RefM —
RefM[A]
models a mutable reference to a value of typeA
in which we can store immutable data, and update it atomically and effectfully.
- RefM —
- Queue — A
Queue
is an asynchronous queue that never blocks, which is safe for multiple concurrent producers and consumers.
Synchronization aids​
- ConcurrentMap — A Map wrapper over
java.util.concurrent.ConcurrentHashMap
- ConcurrentSet — A Set implementation over
java.util.concurrent.ConcurrentHashMap
- CountdownLatch — A synchronization aid that allows one or more fibers to wait until a set of operations being performed in other fibers completes.
- CyclicBarrier — A synchronization aid that allows a set of fibers to all wait for each other to reach a common barrier point.
STM​
- STM - An
STM
represents an effect that can be performed transactionally resulting in a failure or success. - TArray - A
TArray
is an array of mutable references that can participate in transactions. - TSet - A
TSet
is a mutable set that can participate in transactions. - TMap - A
TMap
is a mutable map that can participate in transactions. - TRef - A
TRef
is a mutable reference to an immutable value that can participate in transactions. - TPriorityQueue - A
TPriorityQueue
is a mutable priority queue that can participate in transactions. - TPromise - A
TPromise
is a mutable reference that can be set exactly once and can participate in transactions. - TQueue - A
TQueue
is a mutable queue that can participate in transactions. - TReentrantLock - A
TReentrantLock
is a reentrant read / write lock that can be composed. - TSemaphore - A
TSemaphore
is a semaphore that can participate in transactions.
Resource Management​
- Managed — A
Managed
is a value that describes a perishable resource that may be consumed only once inside a given scope.
Streaming​
The following datatypes can be found in ZIO streams library:
- ZStream — A
ZStream
is a lazy, concurrent, asynchronous source of values. - ZSink — A
ZSink
is a consumer of values from aZStream
, which may produces a value when it has consumed enough.
Miscellaneous​
- Chunk — ZIO
Chunk
: Fast, Pure Alternative to Arrays - Schedule — A
Schedule
is a model of a recurring schedule, which can be used for repeating successfulIO
values, or retrying failedIO
values.
To learn more about these data types, please explore the pages above, or check out the Scaladoc documentation.