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.