Skip to content
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

Contravariant F and optionals #813

Merged
merged 8 commits into from
Jan 27, 2023

Conversation

sviezypan
Copy link
Collaborator

The recent changes that started using macros to verify where, inserts. group by etc made possible to get rid of Features.Union[_, _] and start using intersection types wherever F composes.
So the phantom type F of x in
val x = name ++ age
will be Features.Source["name"] with Features.Source["age"] instead of
Features.Union[Features.Source["name"], Features.Source["age"]]

Its possible now to make F contravariant which gives us nice type inference and makes working with dynamic queries nicer. The example of #583 is now possible.

// before
List(where1, where2, where3)
     .fold[Expr[_, TableType, Boolean]](Expr.literal(true))(_ && _)

// now
List(where1, where2, where3)
   .fold(Expr.literal(true))(_ && _)

This PR also makes changes to working with nullable columns.
Let's say that link describes a nullable column and has a type Option[String].
Instead of always having to use Option("some link"), users have more possibilities

      select(cityName).from(city).where(link === Option(""))
      select(cityName).from(city).where(link === Some(""))
      select(cityName).from(city).where(Some("") === link)

      select(cityName).from(city).where(link === None)
      select(cityName).from(city).where(None === link)

      select(cityName).from(city).where(link === "")
      select(cityName).from(city).where(" " === link)

@sviezypan sviezypan requested a review from a team as a code owner January 19, 2023 07:03
Comment on lines 8 to 11
implicit def materializeWhereIsSound[WhereF, GroupByF]: WhereIsSound[WhereF, GroupByF] = {

WhereCanBeCalled[WhereF, GroupByF]()
}
Copy link
Member

Choose a reason for hiding this comment

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

I suppose this should go back to the original formatting.

Suggested change
implicit def materializeWhereIsSound[WhereF, GroupByF]: WhereIsSound[WhereF, GroupByF] = {
WhereCanBeCalled[WhereF, GroupByF]()
}
implicit def materializeWhereIsSound[WhereF, GroupByF]: WhereIsSound[WhereF, GroupByF] = WhereCanBeCalled[WhereF, GroupByF]()

@jczuchnowski jczuchnowski merged commit f96a932 into zio:master Jan 27, 2023
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.

None yet

2 participants