Skip to content

Instantly share code, notes, and snippets.

@nightscape
Created May 19, 2016 21:36
Show Gist options
  • Save nightscape/63f475338968457bf1b5c952fb2c70bb to your computer and use it in GitHub Desktop.
Save nightscape/63f475338968457bf1b5c952fb2c70bb to your computer and use it in GitHub Desktop.
Trying to apply shapeless LiftAll instances to an HList
import shapeless._
import ops.hlist.LiftAll
import shapeless._
import syntax.singleton._
import shapeless.ops.hlist.ZipWithKeys
case class SingletonOf[T, U](value: U)
object SingletonOf {
implicit def mkSingletonOf[T <: AnyRef](implicit t: T): SingletonOf[T, t.type] = SingletonOf(t)
}
trait Showable[T] {
def show(t: T): String
}
object Showable {
implicit def stringShowable = new Showable[String] {
def show(t: String) = s"String: $t"
}
}
def test[L <: HList, U <: { type Out <: HList }](l: L)(
implicit
zippable: ZipWithKeys[L, U#Out],
showable: LiftAll[Showable, L],
allShowable: SingletonOf[LiftAll[Showable, L], U]
) =
showable.instances.asInstanceOf[U#Out].zipWithKeys(l)
test("foo" :: HNil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment