-
-
Save ahjohannessen/2eb5c6cb4abc3c28762240a93b6eedc9 to your computer and use it in GitHub Desktop.
ConnectionIO Final Tagless Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import doobie._ | |
import doobie.implicits._ | |
// Something for FunctionK ~> | |
trait Foo[F[_]]{ | |
def getFoo: F[Bar] | |
} | |
object Foo { | |
case class Bar(x: Int) | |
object Bar { | |
implicit val metaBar: Meta[Bar] = Meta[Int].imap(Bar(_), _.x) | |
} | |
// For Metadata Testing | |
private[Foo] val getBar : Query0[Bar] = sql"SELECT 1".query[Bar] | |
private def connectIOTrait: Foo[ConnectionIO] = new Foo[ConnectionIO]{ | |
def getFoo: ConnectionIO[Bar] = getBar.unique | |
} | |
def mapK[F[_], G[_]](foo: Foo[F])(f: F ~> G): Foo[G] = new Foo[G]{ | |
def getFoo: G[Bar] = f(foo.getFoo) | |
} | |
def impl[F[_]](t: Transactor[F]): Foo[F] = connectIOTrait.mapK(_.transact(t)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment