Skip to main content
Version: 2.x

Zooming In on Nested Values

Optionโ€‹

We can extract a value from a Some using ZIO#some and then we can unsome it again using ZIO#unsome:

ZIO.attempt(Option("something")) // ZIO[Any, Throwable, Option[String]]
.some // ZIO[Any, Option[Throwable], String]
.unsome // ZIO[Any, Throwable, Option[String]]

Eitherโ€‹

With Either ZIO values, we can zoom in or out on the left or right side of an Either, as well as we can do the inverse and zoom out:

import zio._

val eitherEffect: ZIO[Any, Exception, Either[String, Int]] = ???

eitherEffect // ZIO[Any, Exception, Either[String, Int]]
.left // ZIO[Any, Either[Exception, Int], String]
.unleft // ZIO[Any, Exception, Either[String, Int]]

eitherEffect // ZIO[Any, Exception, Either[String, Int]]
.right // ZIO[Any, Either[String, Exception], Int]
.unright // ZIO[Any, Exception, Either[String, Int]]

ZIO Chat

Hello! ๐Ÿ˜Š I'm your ZIO Chat Bot, designed to be your go-to resource for all things ZIO! Whether you're new to this powerful functional effect system or a seasoned pro, I'm here to assist you. ZIO empowers you to build concurrent and resilient applications in Scala, offering referential transparency, composable data types, type-safety, and more. So, go ahead and ask me anything about ZIO โ€“ I'm here to provide the answers you need! ๐Ÿค–