Created
February 1, 2014 12:05
-
-
Save matthandlersux/8751399 to your computer and use it in GitHub Desktop.
possible way to make easily updatable case class objects
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
trait Base[T] { | |
val id: Option[String] | |
def copyId(id: String): T | |
} | |
case class Test2(id: Option[String], other: String) extends Base[Test2] { | |
def copyId(id: String) = copy(id=Some(id)) | |
} | |
def updateId[T <: Base[T]](obj: T, id: String) = obj.copyId(id) | |
val y = Test2(None, "hmm") | |
assert(updateId(y, "!!!") == Test2(Some("!!!"), "hmm")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment