Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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!

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 force-pushed the zstream-error-combinators branch from e5a5f94 to 79f9daa Compare August 22, 2019 04:19
@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

Development

Successfully merging this pull request may close these issues.

Add provide and provideSome methods to ZStream Generalize ZStream with input/output error types to allow for combinators like mapError

5 participants