Skip to content

Instantly share code, notes, and snippets.

@b-studios
Created December 20, 2017 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b-studios/51cb53000cb74fbc39751791a8d4b4ed to your computer and use it in GitHub Desktop.
Save b-studios/51cb53000cb74fbc39751791a8d4b4ed to your computer and use it in GitHub Desktop.
Implicits in Unapply
// probably could be used for some cool type state stuff
sealed trait HList
case class HCons[A, R <: HList](head: A, tail: R) extends HList {
def ::[B](b: B): B :+: A :+: R = HCons(b, this)
}
case object HNil extends HList {
def ::[A](a: A): A :+: HNil = HCons(a, this)
}
type HNil = HNil.type
type :+:[A, R <: HList] = HCons[A, R]
sealed trait In[E, L <: HList] {}
object In {
implicit def here[E, L <: HList]: E In (E :+: L) = ???
implicit def there[E, R, L <: HList](implicit rest: E In L): E In (R :+: L) = ???
}
object IntElem {
def unapply[L <: HList](l: L)(implicit f: Int In L): Option[Int] = ???
}
val l = true :: 4 :: "foo" :: HNil
l match {
case IntElem(n) => ???
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment