Generalize Has.AreHas to Has.Union #4013
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #3997.
There has been a desire by library authors to generalize over the types
_ <: Has[_]andAnyto describe conceptually "the set of all environmental requirements that can be combined generically".This PR changes the encoding of
Has.AreHas, which describes the capability to combine two types to form their intersection, from:to:
Instances are then provided for combinations of
HaswithHas,HaswithAny,AnywithHas, andAnywithAny.The biggest disadvantage of this proposal I can see is we lose the contravariance on the type parameters of
RandR1. Previously, we could say that ifRandR1are subtypes ofHas, thenR0 <: RandR00 <: R1are also subtypes ofHasand so can be combined generically. But now ifRisAnyit is not the case that we can combine subtypes ofRgenerically. This requires type annotations in the implementation of a couple of additionalZLayercombinators, but it only required one change to the API (adding an additionalROut1 >: ROutparameter in+!+for variance) and no additional type annotations in any of the tests, so I think the impact will be limited to library authors who are writing their own combinators to combine environment types generically.We don't gain a lot from this capability in our own library but it avoids the need for libraries like
zio-grpcto implement it themselves and potentially provides them with a common way to do so.Copying @thesamet.