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

Skip to content

Conversation

@adamgfraser
Copy link
Contributor

The current signature of checkM is:

final def checkM[R, E, A](rv: Gen[R, A])(test: A => ZIO[R, E, TestResult]): ZIO[R, E, TestResult]

The curried syntax is quite nice for ergonomics and writing tests in a property based style, but there can be a type inference issue if the test requires an additional environment beyond what the generator does because the compiler determines the R type after looking at the first parameter without considering the second.

This PR resolves this by changing the signature to be:

final def checkM[R, R1 <: R, E, A](rv: Gen[R, A])(test: A => ZIO[R1, E, TestResult]): ZIO[R1, E, TestResult]

@adamgfraser adamgfraser requested a review from jdegoes November 7, 2019 16:07
Copy link
Member

@jdegoes jdegoes left a comment

Choose a reason for hiding this comment

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

This looks great to me. The partial type application trick used in things like timeoutTo in ZIO could also work (and in fact, works better in some cases). Did you try this on anything else to make sure it has the intended effects on type inference?

@adamgfraser
Copy link
Contributor Author

Yes, I thought about that and agree that would work too.

In my experiments the type inference worked quite well. The main thing I was worried about was that since we are stating that R1 <: R there would be an issue if R1 was actually a supertype of R (e.g. the generator requires Random but the test doesn't require any effect). However, since R is contravariant the type can automatically be narrowed which I think may make this work a little better for the R parameter than the other parameters. I tested it with an effect that required a completely different environment (e.g. generator requires random, test requires clock) and that worked as well. We have also used this pattern in Live#withLive and I haven't seen any issues there.

@jdegoes
Copy link
Member

jdegoes commented Nov 7, 2019

@adamgfraser All right, sounds great!

@jdegoes jdegoes merged commit 9a071bf into zio:master Nov 7, 2019
@adamgfraser adamgfraser deleted the check branch November 7, 2019 21:47
Twizty pushed a commit to Twizty/zio that referenced this pull request Nov 13, 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.

2 participants