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
Add error and environment combinators for ZStream #1427
Conversation
Yes! |
6ffa3b4
to
3c14648
Compare
Awesome. We'll finally have this in 🎆 |
@iravid This is the look of things clicking into place. 😄 💪 |
for { | ||
finalizer <- Ref.make[Exit[_, _] => ZIO[R1, Nothing, Any]](_ => UIO.unit).toManaged_ | ||
_ <- ZManaged.finalizerExit(e => finalizer.get.flatMap(_.apply(e))) | ||
selfInputStream <- Ref.make[InputStream[R, E, A]](InputStream.end).toManaged_ |
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.
This pattern occurs so pervasively I think we should write a combinator to handle it (finalizer
?). Basically creating a Ref
, with some default action, then running some code, updating the default, and finally ensuring the finalizer is run at the end. Could be reasonably nice to use with ZManaged
, I think.
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.
Good idea. This looked like a combinator for ZManaged
- ZManaged.finalizerRef
.
* Provides the stream with its required environment, which eliminates | ||
* its dependency on `R`. | ||
*/ | ||
final def provide(r: R): Stream[E, 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.
Wonderful to see all these!
* | ||
* See also [[ZStream#catchAll]]. | ||
*/ | ||
final def orElse[R1 <: R, E2, A1 >: A](that: => ZStream[R1, E2, A1]): ZStream[R1, E2, A1] = |
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.
Love it!
@@ -1476,6 +1640,30 @@ object ZStream extends ZStreamPlatformSpecific { | |||
def dieMessage(m: String): InputStream[Any, Nothing, Nothing] = UIO.dieMessage(m) | |||
def done[E, A](e: Exit[E, A]): InputStream[Any, E, A] = IO.done(e).mapError(Some(_)) | |||
def fromPromise[E, A](p: Promise[E, A]): InputStream[Any, E, A] = p.await.mapError(Some(_)) | |||
|
|||
def sequenceCause[E](c: Cause[Option[E]]): Option[Cause[E]] = |
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.
sequenceCauseOption
?
Awesome. Great job getting all those changes in. 🙏 🎉 |
b8afd68
to
e5a5f94
Compare
e5a5f94
to
79f9daa
Compare
* is yielded as the result of the effect, allowing for control flows that require | ||
* mutating finalizers. | ||
*/ | ||
final def finalizerRef[R]( |
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.
This looks great!
* is yielded as the result of the effect, allowing for control flows that require | ||
* mutating finalizers. | ||
*/ | ||
final def finalizerRef[R]( |
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.
This looks great!
At last,
Resolves #634
Resolves #817
cc @runtologist @mschuwalow