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

Skip to content

Conversation

@jdegoes
Copy link
Member

@jdegoes jdegoes commented Mar 3, 2019

This is mainly to fix semantics of provide which was incorrectly using "last one wins" instead of "scoped provision". However, I also improved type inference.

@jdegoes jdegoes requested a review from wi101 March 3, 2019 18:38
type Task[+A] = ZIO[Any, Throwable, A]
type UIO[+A] = ZIO[Any, Nothing, A]

implicit class ZIOInvarant[R, E, A](val self: ZIO[R, E, A]) extends AnyVal {
Copy link
Member

Choose a reason for hiding this comment

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

typo in Invariant

Also, I think that if you put it in the ZIO companion object, it won't need to be imported.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed both

@LGLO
Copy link
Contributor

LGLO commented Mar 3, 2019

I can't see how using ZIO.bracket doesn't allocate two objects: BracketAcquire and BracketRelease.
If my computation will use bracket in hot path (for example to acquire some Ref or Semaphore) then it will cause many allocations.

EDIT: I was thinking about implicit case class, like ZIOInvariant but together with phantom type but then I came to conclusion that it's not worth it.

@jdegoes
Copy link
Member Author

jdegoes commented Mar 3, 2019

@LGLO Did you see if we can fix by some other means? Sorry overnight 17 pull requests appeared and I am way behind on reviews. Will do more tomorrow.

My other idea is to have a ZIO.bracket which takes ALL parameters at once. Then the "syntax sugar" method simply delegates to this one. This way if you have it in a hot path, you just use the uncurried form...

@LGLO
Copy link
Contributor

LGLO commented Mar 3, 2019

@jdegoes I made this uncurried version but TBH I don't really like it if was the only version available. Having both looks good to me.

Is ZIOInvarant required? Why is it better than instance methods?

@jdegoes
Copy link
Member Author

jdegoes commented Mar 3, 2019

@LGLO Can you submit a pull request to my pull request? 😄

ZIOInvariant improves type inference by eliminating one layer of widening (if we put it onto ZIO directly, then we have to widen all parameters).

@LGLO
Copy link
Contributor

LGLO commented Mar 3, 2019 via email

Copy link
Member

@regiskuckaertz regiskuckaertz left a comment

Choose a reason for hiding this comment

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

Bye bye type annotations 👋 Just a few questions but otherwise this looks great!

* Adds an effect to consumption of every element of the stream.
*/
final def withEffect[R1 <: R, E1 >: E](f: A => ZIO[R1, E1, Unit]): Stream[R1, E1, A] =
final def tap[R1 <: R, E1 >: E](f: A => ZIO[R1, E1, Unit]): Stream[R1, E1, A] =
Copy link
Member

Choose a reason for hiding this comment

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

f: A => ZIO[R1, E1, _]?

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 catch 👍


final def withEffect[R1 <: R, E1 >: E](f0: A => ZIO[R1, E1, Unit]): StreamChunk[R1, E1, A] =
StreamChunk(chunks.withEffect[R1, E1] { as =>
final def tap[R1 <: R, E1 >: E](f0: A => ZIO[R1, E1, Unit]): StreamChunk[R1, E1, A] =
Copy link
Member

Choose a reason for hiding this comment

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

f0: A => ZIO[R1, E1, _]?

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 catch 👍

iravid
iravid previously approved these changes Mar 6, 2019
* result is either succeeded with a value `A`, or failed with a `Cause[E]`.
*/
sealed abstract class Exit[+E, +A] extends Product with Serializable { self =>
sealed trait Exit[+E, +A] extends Product with Serializable { self =>
Copy link
Member

Choose a reason for hiding this comment

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

Interesting, why the change? I thought abstract classes generate more efficient bytecode most of the time.

Copy link
Member Author

Choose a reason for hiding this comment

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

We dropped Scala 2.11. The main reason for abstract class is to avoid breaking backward binary compatibility on adding a method with a default implementation.

* effects of this effect.
*/
final def const[B](b: => B): ZIO[R, E, B] = self.map(_ => b)
final def const[B](b: => B): ZIO[R, E, B] = self map (_ => b)
Copy link
Member

Choose a reason for hiding this comment

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

OCD much 😂

Copy link
Member Author

Choose a reason for hiding this comment

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

You have no idea 😆

ghostdogpr
ghostdogpr previously approved these changes Mar 6, 2019
@jdegoes jdegoes dismissed stale reviews from ghostdogpr and iravid via 42c6e5b March 6, 2019 12:17
}

final def seq[E1 >: E, C](that: Sink[R, E1, A, A, C]): Sink[R, E1, A, A, (B, C)] =
final def zip[E1 >: E, C](that: Sink[R, E1, A, A, C]): Sink[R, E1, A, A, (B, C)] =
Copy link
Member

Choose a reason for hiding this comment

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

We could also allow narrowing of R here. I'll open a separate issue for this

@jdegoes jdegoes merged commit 69bac60 into zio:master Mar 6, 2019
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.

5 participants