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

Doobie integration #107

Open
ioleo opened this issue Aug 12, 2023 · 1 comment
Open

Doobie integration #107

ioleo opened this issue Aug 12, 2023 · 1 comment

Comments

@ioleo
Copy link

ioleo commented Aug 12, 2023

It would be great to see doobie integration (Get and Put instances for arbitrary newtypes).

@ioleo
Copy link
Author

ioleo commented Aug 12, 2023

For now I'm using

import cats.Show
import monix.newtypes.*

given newtypesGet[T, S](using
  B: HasBuilder.Aux[T, S],
  G: Get[S],
  V: Show[S]
): Get[T] =
  G.temap(s => B.build(s).left.map(ex => s"Invalid ${ex.message.fold("")(m => s"$m")}"))

given newtypesPut[T, S](using
  E: HasExtractor.Aux[T, S],
  P: Put[S]
): Put[T] =
  P.contramap(t => E.extract(t))

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

No branches or pull requests

1 participant