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

Skip to content

Conversation

@adamgfraser
Copy link
Contributor

Minor improvements to support for laws for parameterized types based on initial experience working with them:

  1. It is nice for the user not to have to create their own GenF for standard types, so provides those.
  2. Adds a few more type aliases.
  3. Adds the law constructor for one F[A] and two functions A => B and B => C for contravariant and invariant types. We still have a little problem of needing more law constructors for different shapes of inputs, but the user experience is so much better when we provide them that I think we just try to do it for reasonable combinations that come up.

@adamgfraser adamgfraser requested a review from jdegoes April 14, 2020 03:25
/**
* Constructs a law from a pure function taking three parameters.
*/
abstract class Law3Function[-CapsF[_[-_]], -Caps[_]](label: String) extends Contravariant[CapsF, Caps, Any] {
Copy link
Member

Choose a reason for hiding this comment

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

This is always a function compose law, so maybe LawCompose or LawFunctionCompose?

Copy link
Member

Choose a reason for hiding this comment

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

The other possibility is to push it into ZIO Prelude as a class in the companion object of the associated type class (Covariant).

Copy link
Contributor Author

@adamgfraser adamgfraser Apr 14, 2020

Choose a reason for hiding this comment

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

I like the renaming. Pushing it to ZIO Prelude is interesting. The disadvantage there would be that it is less ergonomic if someone else wants to implement their own law with the same shape, or even if we want to do so somewhere else in ZIO Prelude. But it does solve the problem that we don't necessarily know at the ZIO Test level the shape of all the laws we will want to test.

/**
* Constructs a law from a pure function taking three parameters.
*/
abstract class Law3Function[-CapsF[_[_]], -Caps[_]](label: String) extends Invariant[CapsF, Caps, Any] { self =>
Copy link
Member

Choose a reason for hiding this comment

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

For invariant, the likely form this law would take would be <=> instead of =>. So I'm not sure whether to put that in here or to defer it downstream. Thinking about it, nothing stops us from including these type classes in ZIO Prelude, so users can do things like new zio.prelude.Invaraint.ComposeLaw.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, for this one in particular we have to be quite careful in the way we generate the pair of functions so they form an equivalence relation.

@adamgfraser
Copy link
Contributor Author

Renamed covariant and contravariant versions to ComposeLaw and removed the invariant version.

@adamgfraser adamgfraser requested a review from jdegoes April 15, 2020 12:20
jdegoes
jdegoes previously approved these changes Apr 25, 2020
@jdegoes
Copy link
Member

jdegoes commented Apr 25, 2020

@adamgfraser Good to merge when conflicts are fixed!

@adamgfraser
Copy link
Contributor Author

@jdegoes All set.

@adamgfraser adamgfraser requested a review from jdegoes April 25, 2020 01:56
@adamgfraser
Copy link
Contributor Author

@jdegoes Could I get a review on this? I added a FlattenLaw and more importantly unsealed the law traits so that downstream libraries can implement their own laws when the "shapes" of laws they need don't match the ones already provided.

@jdegoes jdegoes merged commit 2d015ef into zio:master May 10, 2020
@jdegoes
Copy link
Member

jdegoes commented May 10, 2020

@adamgfraser I like that direction (opening up the trait). If placed in the companion object of the corresponding type class, it should be easy for users to reuse these laws and know where to look for them. 👍

@adamgfraser adamgfraser deleted the laws branch May 10, 2020 17:37
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