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
Implement CanFail #2049
Implement CanFail #2049
Conversation
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.
Should we add this to ZSink
and ZStream
combinators as well?
@vasilmkd Yes definitely. |
@adamgfraser
Importantly, behavior of ambiguous implicits changed in Dotty, so I'm not sure the same approach would work there... |
@neko-kai Yes, we should definitely test this. I also wonder if we should add this functionality to ZIO Test. You’re right about Dotty. We need to use a slight variation of this technique to work across all platforms. I’ll push a commit to fix that shortly. |
@neko-kai @adamgfraser Please no dependency on Shapeless. If we do anything for this, it should be possible to support Scala 2.x and 3.x simultaneously. |
Okay, so to summarize I rolled back Open questions / next steps:
|
It may not be worth it but we could potentially do the same thing with the |
Of course it's worth it. ZIO is a next-generation effect system after all. 💪 |
@neko-kai argued to leave them on grounds that I think it is a valid argument, it just concerned me when I saw, e.g. What do you think?
Makes sense.
I think you're right about this,
Agreed, if we had something that was cross Scala (2.11 - Dotty), it could make sense to add to ZIO Test, and that's precisely the case when I'd feel comfortable adding it here. |
Probably a good idea to watch this talk, I found it pretty fascinating when I first saw it. There might be some good hints when it comes to naming as well: |
@jdegoes I don’t think I will add back the changes to I have also been working on something to test that code does not compile so I will post that shortly, though that will be in a separate PR. Did you have any interest in doing something similar for the environment type? |
ZIO
ZManaged
ZStream
ZStreamChunk
|
This is ready for another review. |
OK, sounds great!
Yes, I think it's worthwhile to do that. Maybe |
Okay, great! I will open a separate PR to do the same thing for the environment type. Maybe |
Like |
implicit final def canFail[E]: CanFail[E] = CanFail | ||
|
||
implicit final val canFailAmbiguous1: CanFail[Nothing] = CanFail | ||
implicit final val canFailAmbiguous2: CanFail[Nothing] = CanFail |
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.
For my own understanding, why is there two such values? Also it may be useful to add an explanatory comment for the future.
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 want implicit search to fail when E =:= Nothing
so we create two identical instances of CanFail[Nothing]
to ensure that the result will always be ambiguous. I can add some documentation when I do the same thing the environment type.
I'm on it! |
* implement CanFail * fix typo * cache values * update documentation * fix type inference issue * turn off warning for unused implicit parameters * fix dotty compatibility issue * address review comments * add back fold and foldM * add <> * add ZManaged * add ZStream * add ZStreamChunk * cleanup * remove extraneous type parameter
* implement CanFail * fix typo * cache values * update documentation * fix type inference issue * turn off warning for unused implicit parameters * fix dotty compatibility issue * address review comments * add back fold and foldM * add <> * add ZManaged * add ZStream * add ZStreamChunk * cleanup * remove extraneous type parameter
Resolves #2047.
Adds a new implicit instance
CanFail[E]
which provides implicit evidence that an effect with an error typeE
can fail, that is thatE
is not equal toNothing
. Requires such evidence to exist for ZIO combinators such asorElse
that only make sense if an effect can fail.Not implemented yet is adding annotations so that the implicit type does not appear in the Scaladoc. It looks like this has to be done through the
@useCase
annotation, but one watch out there is it requires you to specify the "simplified" type signature as a text string, so there is some risk that the documentation gets out of sync with the actual type signature since it is not tied to the code.Also not implemented is applying this technique to other effect types such as
ZManaged
andZStream
.