Last active
September 21, 2018 15:30
-
-
Save ChristopherDavenport/8cd173f372e59227b4208f24e51adbb4 to your computer and use it in GitHub Desktop.
ConnectionIO Final Tagless Example
This file contains hidden or 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