Skip to content

Instantly share code, notes, and snippets.

@ChristopherDavenport
Last active September 21, 2018 15:30

Revisions

  1. ChristopherDavenport revised this gist Sep 21, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Foo.scala
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ object Foo {
    }

    def mapK[F[_], G[_]](foo: Foo[F])(f: F ~> G): Foo[G] = new Foo[G]{
    def getFoo: G[Foo] = f(foo.getFoo)
    def getFoo: G[Bar] = f(foo.getFoo)
    }
    def impl[F[_]](t: Transactor[F]): Foo[F] = connectIOTrait.mapK(_.transact(t))
    }
  2. ChristopherDavenport revised this gist Sep 21, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Foo.scala
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ object Foo {
    implicit val metaBar: Meta[Bar] = Meta[Int].imap(Bar(_), _.x)
    }
    // For Metadata Testing
    private[Foo] val getBar : Query0[MyFoo] = sql"SELECT 1".query[Bar]
    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
  3. ChristopherDavenport revised this gist Sep 21, 2018. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions Foo.scala
    Original file line number Diff line number Diff line change
    @@ -5,19 +5,19 @@ import doobie.implicits._
    // Something for FunctionK ~>

    trait Foo[F[_]]{
    def getFoo: F[MyFoo]
    def getFoo: F[Bar]
    }

    object Foo {
    case class MyFoo(x: Int)
    object MyFoo {
    implicit val metaFoo: Meta[MyFoo] = Meta[Int].imap(MyFoo(_), _.x)
    case class Bar(x: Int)
    object Bar {
    implicit val metaBar: Meta[Bar] = Meta[Int].imap(Bar(_), _.x)
    }
    // For Metadata Testing
    private[Foo] val getMyFoo : Query0[MyFoo] = sql"SELECT 1".query[MyFoo]
    private[Foo] val getBar : Query0[MyFoo] = sql"SELECT 1".query[Bar]

    private def connectIOTrait: Foo[ConnectionIO] = new Foo[ConnectionIO]{
    def getFoo: ConnectionIO[MyFoo] = getMyFoo.unique
    def getFoo: ConnectionIO[Bar] = getBar.unique
    }

    def mapK[F[_], G[_]](foo: Foo[F])(f: F ~> G): Foo[G] = new Foo[G]{
  4. ChristopherDavenport created this gist Sep 21, 2018.
    27 changes: 27 additions & 0 deletions Foo.scala
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@

    import doobie._
    import doobie.implicits._

    // Something for FunctionK ~>

    trait Foo[F[_]]{
    def getFoo: F[MyFoo]
    }

    object Foo {
    case class MyFoo(x: Int)
    object MyFoo {
    implicit val metaFoo: Meta[MyFoo] = Meta[Int].imap(MyFoo(_), _.x)
    }
    // For Metadata Testing
    private[Foo] val getMyFoo : Query0[MyFoo] = sql"SELECT 1".query[MyFoo]

    private def connectIOTrait: Foo[ConnectionIO] = new Foo[ConnectionIO]{
    def getFoo: ConnectionIO[MyFoo] = getMyFoo.unique
    }

    def mapK[F[_], G[_]](foo: Foo[F])(f: F ~> G): Foo[G] = new Foo[G]{
    def getFoo: G[Foo] = f(foo.getFoo)
    }
    def impl[F[_]](t: Transactor[F]): Foo[F] = connectIOTrait.mapK(_.transact(t))
    }