Skip to content

Instantly share code, notes, and snippets.

@p-pavel
Created July 4, 2019 04:37
Show Gist options
  • Save p-pavel/ca20053a7d4ce6d7d353f648cab89960 to your computer and use it in GitHub Desktop.
Save p-pavel/ca20053a7d4ce6d7d353f648cab89960 to your computer and use it in GitHub Desktop.
trait HList {
def ::[A](x: A): A :: this.type
}
trait ::[+Head, +Tail <: HList] extends HList {
val head: Head
val tail: Tail
def ::[A](x: A): A :: this.type = HCons(x,this)
}
final case class HCons[+Head, +Tail <: HList](head: Head, tail: Tail) extends (Head :: Tail) {
override def toString: String = s"$head :: $tail"
}
trait HNil extends HList
final case object HNil extends HNil {
def ::[A](x: A): A :: this.type = HCons(x, this)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment