Last active
April 16, 2018 19:14
-
-
Save jto/ee1b431ab8a19236b8ba43e0b2653da3 to your computer and use it in GitHub Desktop.
VecHlist.scala
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
final object F { | |
type HList //<: Product with Serializable | |
type HNil <: HList | |
type #:[+H, +T <: HList] <: HList | |
implicit class HListBuilder[T <: HList](h: T) { | |
def #:[H](a: H): H #: T = F.#:(a, h) | |
} | |
object #: { | |
def unapply[H, T <: HList](h: H #: T): Option[(H, T)] = { | |
val v = h.asInstanceOf[Vector[Any]] | |
val head = v.head.asInstanceOf[H] | |
val tail = v.tail.asInstanceOf[T] | |
Option((head, tail)) | |
} | |
def apply[H, T <: HList](h: H, t: T): H #: T = | |
(h +: t.asInstanceOf[Vector[Any]]) | |
.asInstanceOf[H #: T] | |
} | |
val HNil: HNil = Vector().asInstanceOf[HNil] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment