Skip to content
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

Merged
merged 2 commits into from Aug 22, 2019

Conversation

iravid
Copy link
Member

@iravid iravid commented Aug 17, 2019

At last,
Resolves #634
Resolves #817

cc @runtologist @mschuwalow

@iravid iravid requested a review from jdegoes August 17, 2019 17:30
@adamgfraser
Copy link
Contributor

Yes!

@mschuwalow
Copy link
Member

Awesome. We'll finally have this in 🎆

@jdegoes
Copy link
Member

jdegoes commented Aug 18, 2019

@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_
Copy link
Member

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.

Copy link
Member Author

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] =
Copy link
Member

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] =
Copy link
Member

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]] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sequenceCauseOption?

@runtologist
Copy link
Member

Awesome. Great job getting all those changes in. 🙏 🎉

@iravid iravid force-pushed the zstream-error-combinators branch 2 times, most recently from b8afd68 to e5a5f94 Compare August 21, 2019 20:06
@iravid iravid merged commit bcaff95 into zio:master Aug 22, 2019
* is yielded as the result of the effect, allowing for control flows that require
* mutating finalizers.
*/
final def finalizerRef[R](
Copy link
Member

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](
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants