-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix semantics of provide
and improve type inference
#597
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
@@ -26,6 +26,14 @@ package object zio extends EitherCompat { | |||
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 { |
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.
typo in Invariant
Also, I think that if you put it in the ZIO
companion object, it won't need to be imported.
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.
Fixed both
I can't see how using EDIT: I was thinking about implicit case class, like |
@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... |
@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 |
@LGLO Can you submit a pull request to my pull request? 😄
|
Happy to help, but tomorrow, if that isn't a problem.
niedz., 3 mar 2019, 22:45: John A. De Goes <notifications@github.com>
napisał(a):
… @LGLO <https://github.com/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).
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#597 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACkc0SMkJ70tSnlUQaCD8lxOIG6wOaAOks5vTEJugaJpZM4bbKB5>
.
|
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.
Bye bye type annotations 👋 Just a few questions but otherwise this looks great!
@@ -530,7 +530,7 @@ trait Stream[-R, +E, +A] extends Serializable { self => | |||
/** | |||
* 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] = |
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.
f: A => ZIO[R1, E1, _]
?
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 catch 👍
@@ -66,8 +66,8 @@ trait StreamChunk[-R, +E, @specialized +A] { self => | |||
final def foreach[R1 <: R, E1 >: E](f: A => ZIO[R1, E1, Unit]): ZIO[R1, E1, Unit] = | |||
foreachWhile[R1, E1](f(_).const(true)) | |||
|
|||
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] = |
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.
f0: A => ZIO[R1, E1, _]
?
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 catch 👍
@@ -20,7 +20,7 @@ package scalaz.zio | |||
* An `Exit[E, A]` describes the result of executing an `IO` value. The | |||
* 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 => |
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.
Interesting, why the change? I thought abstract classes generate more efficient bytecode most of the time.
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.
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.
} yield l.succeed(()) *> p.await | ||
|
||
/** | ||
* Maps this effect to the specified constant while preserving the | ||
* 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) |
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.
OCD much 😂
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.
You have no idea 😆
@@ -765,20 +765,26 @@ object Sink { | |||
} | |||
} | |||
|
|||
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)] = |
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.
We could also allow narrowing of R
here. I'll open a separate issue for this
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.