-
-
Save misberner/eec5e74f759353da3384 to your computer and use it in GitHub Desktop.
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
case class MyClass(intAttr: Int, listAttr: List[String], mapAttr: Map[String,Int]) { | |
def updated( | |
intAttr : Int => Int = identity, | |
listAttr : List[String] => List[String] = identity, | |
mapAttr : Map[String,Int] => Map[String,Int] = identity) = { | |
MyClass(intAttr(this.intAttr), listAttr(this.listAttr), mapAttr(this.mapAttr)) | |
} | |
} | |
object Test extends App { | |
override def main(args: Array[String]) { | |
val x = MyClass(42, List("foo", "bar"), Map("baz" -> 37, "qux" -> 1000)) | |
val y = x.updated(intAttr = _ * 100, listAttr = "42" :: _) // MyClass(4200, ...) | |
val z = y.updated(listAttr = _.reverse, mapAttr = _.updated("baz", 73)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment