Created
June 12, 2017 17:16
-
-
Save jiamingd/f7a48f5b2f9b9d30897812fa3a86c380 to your computer and use it in GitHub Desktop.
Typed return value can make the duplicate impl, the boilerplates gone, and more type safe. This is some drill and improvement on sample of "Scala in Depth"
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
object HLists { | |
trait HList { | |
type ConResult[A] <: HList | |
def ::[A](a: A): ConResult[A] | |
} | |
case class HCol[H, T](h: H, t: T) extends HList { | |
override type ConResult[A] = HCol[A, HCol[H, T]] | |
override def ::[A](a: A): ConResult[A] = { | |
HCol[A, HCol[H, T]](a, this) | |
} | |
} | |
case object HNil { | |
type ConResult[A] = HCol[A, HNil.type] | |
def ::[A](a: A): ConResult[A] = HCol(a, HNil) | |
} | |
} | |
import HLists._ | |
val x = "ok"::Boolean::2L::HNil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try Line 13 with: ConResult[A](a, this)