Created
July 31, 2015 15:54
-
-
Save gigiigig/8e16a97ef6bdc6de5a65 to your computer and use it in GitHub Desktop.
Implicit proof that a case class contains certain fields
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 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