Error Channel Operations
ZIO's error channel supports a rich set of transformations beyond simple recovery. These operators let us reshape, inspect, and restructure errors and successes without necessarily resolving the failure — useful when threading error values through a larger computation.
- Map Operations — transform error values with
mapError,mapErrorCause, andmapAttemptwithout recovering from the failure. - Chaining Effects Based on Errors — sequence a second effect that depends on the first effect's typed error using
flatMapError. - Filtering the Success Channel — convert success values that fail a predicate into typed errors using
filterOrFail,filterOrDie, andfilterOrElse. - Tapping Errors — inspect failure values, defects, and
Causegraphs as a side effect without altering the error channel, usingtapError,tapErrorCause, andtapDefect. - Exposing Errors in the Success Channel — move typed failures into the success channel as
Eithervalues usingZIO#either, then submerge them back withZIO#absolve. - Exposing the Cause in the Success Channel — surface the full
Cause[E]graph in the success channel usingZIO#cause, then submerge it withZIO#uncause. - Converting Defects to Failures — turn defects back into typed failures using
absorbandresurrect. - Error Refinement — narrow or widen the typed error channel using
refineOrDie,refineToOrDie,unrefine, andunrefineTo. - Flattening Optional Error Types — collapse
Option[E]error types into plainEusingZIO#flattenErrorOption, providing a default error for theNonecase. - Merging the Error Channel into the Success Channel — collapse the error channel into the success channel using
ZIO#mergewhen both types are compatible, producing an infallible effect. - Flipping Error and Success Channels — swap the error and success channels using
flipandflipWithto apply success-channel operators to errors. - Rejecting Some Success Values — convert select success values into typed failures using
ZIO#rejectandZIO#rejectZIOwith a partial function. - Zooming In on Nested Values — navigate
OptionandEithervalues nested inside ZIO effects usingsome,unsome,left,right, and related operators.