-
Couldn't load subscription status.
- Fork 1.4k
#1217 - operators for option type #1221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
In case it is helpful, here is the work I did on implementing |
| final def some[B](implicit ev: A <:< Option[B]): ZIO[R, Option[E], B] = | ||
| self.foldM(e => ZIO.fail(Some(e)), a => a.fold[ZIO[R, Option[E], B]](ZIO.fail(Option.empty[E]))(ZIO.succeed(_).mapError(_ => Option.empty[E]))) | ||
|
|
||
| final def peelError[E1](implicit ev: E <:< Option[E1]): ZIO[R, E1, Option[A]] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think we should call this optional. Better name than peelError, anyway. Otherwise looks good!
|
@jdegoes @adamgfraser what are the actual use cases for |
|
@jczuchnowski IO.succeed(None).none === IO(())
IO.succeed(Some(1)).none === IO.fail(Option.empty)
IO.fail("Fail").none === IO.fail(Some("Fail"))Fuse error is taking a IO.fail(Some("Fail")).fuseError("Default") === IO.fail("Fail")
IO.fail(None).fuseError("Default") === IO.fail("Default") |
| final def forkOn(ec: ExecutionContext): ZIO[R, E, Fiber[E, A]] = | ||
| self.on(ec).fork | ||
|
|
||
| final def fuseError[E1, E2 <: E1](default: E2)(implicit ev: E <:< Option[E1]): ZIO[R, E1, A] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we call this flattenErrorOption?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely more descriptive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small rename, then good to merge!
Part of work for #1217 . In short - improve working with options: