Created
December 20, 2017 16:45
-
-
Save b-studios/51cb53000cb74fbc39751791a8d4b4ed to your computer and use it in GitHub Desktop.
Implicits in Unapply
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
// 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