Skip to content

Instantly share code, notes, and snippets.

@xevix
Created January 22, 2016 06:32
Show Gist options
  • Save xevix/d5afb6c1f336a9122b56 to your computer and use it in GitHub Desktop.
Save xevix/d5afb6c1f336a9122b56 to your computer and use it in GitHub Desktop.
import shapeless.syntax.std.tuple._
import shapeless._, syntax.singleton._
object ShapelessMain {
def main(args: Array[String]): Unit = {
val l = 23 :: "foo" :: true :: HNil
l(1)
val t = (23, "foo", true)
t(1)
23.narrow
"foo".narrow
val (wTrue, wFalse) = (Witness(true), Witness(false))
type True = wTrue.T
type False = wFalse.T
trait Select[B] {
type Out
}
implicit val selInt = new Select[True] {
type Out = Int
}
implicit val selString = new Select[False] {
type Out = String
}
def select[T](b: WitnessWith[Select])(t: b.Out) = t
select(true)(23)
// select(true)("foo")
// select(false)(23)
select(false)("foo")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment