Skip to content

Instantly share code, notes, and snippets.

@gigiigig
Created July 31, 2015 15:54
Show Gist options
  • Save gigiigig/8e16a97ef6bdc6de5a65 to your computer and use it in GitHub Desktop.
Save gigiigig/8e16a97ef6bdc6de5a65 to your computer and use it in GitHub Desktop.
Implicit proof that a case class contains certain fields
import shapeless._, record._, ops.record._ , syntax.singleton._, labelled._
object console extends App {
case class Foo(i: Int,s: String)
trait Check[L] extends SingletonProductArgs {
def applyProduct[T <: HList, LR <: HList]
(t: T)
(implicit
lg: LabelledGeneric.Aux[L, LR],
sa: SelectAll[LR, T]
): T = t
}
object Check {
implicit def check[T] = new Check[T] {}
}
def foo[T, R <: HList, L]
(t: T)
(implicit
g: Generic.Aux[T, L],
c: Check[L]) = {
val l = c(g.to(t))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment