Skip to content

Instantly share code, notes, and snippets.

@jto
Last active April 16, 2018 19:14
Show Gist options
  • Save jto/ee1b431ab8a19236b8ba43e0b2653da3 to your computer and use it in GitHub Desktop.
Save jto/ee1b431ab8a19236b8ba43e0b2653da3 to your computer and use it in GitHub Desktop.
VecHlist.scala
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