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

Remove the need for specifying R leftover environment (continuation) #24

Merged
merged 6 commits into from
Mar 21, 2021

Conversation

gaelrenoux
Copy link
Owner

OK, I've taken @kitlangton's proposal from #23 and applied it to all *R methods. And behold: no more explicit environment declared when calling those methods! See discussion on that PR for details.

Also fixes the compile test that were not breaking compilation when they should.

@gaelrenoux gaelrenoux added the enhancement New feature or request label Mar 21, 2021
@gaelrenoux gaelrenoux self-assigned this Mar 21, 2021
@gaelrenoux gaelrenoux merged commit 6a5b727 into master Mar 21, 2021
@gaelrenoux gaelrenoux deleted the Remove-need-for-leftover-R branch March 21, 2021 14:14
@hmemcpy
Copy link
Contributor

hmemcpy commented Mar 30, 2021

Hey, sorry to bump this, but I wanted to share something we use internally:

  def transaction[E, A](tx: ZIO[Connection, E, A]): ZIO[Transactor, E, A] =
    Database.transactionOrDie(tx)

  def transaction[R, E, A](tx: ZIO[Connection with R, E, A])(implicit ev: R <:< Has[_]): ZIO[Transactor with R, E, A] =
    Database.transactionOrDieR(tx)

A very thin wrapper, delegating to tranzactio. I was able to create two overloads called transaction. Normally this doesn't work, since [E, A] and [R, E, A] have the same erasure, but turns out that sticking an implicit causes them to be different as far as Scala is concerned!

So I can have my cake and eat it too - a single transaction function (from the user's perspective) that handles either Connection or Connection with R.

Not sure if that ship had sailed (now that you've published v2.0), but maybe you could use this trick and remove the R overloads completely! :)

@gaelrenoux-datadome
Copy link
Contributor

@hmemcpy That's pretty interesting actually, it should work. The good thing is, I can put it into a 2.1.0, and just keep the *R methods as deprecated (there wouldn't be an issue here). I'll look into it (not sure when).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants