Created
December 28, 2012 14:37
-
-
Save anoopelias/4398362 to your computer and use it in GitHub Desktop.
Is there a name for this kind of assignment? See how 'n' is assigned below.
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
scala> case class Name(name:String) | |
defined class Name | |
scala> val a = Name("Anoop") | |
a: Name = Name(Anoop) | |
scala> val Name(n) = a | |
n: String = Anoop | |
scala> |
:-)
worth mentioning is that it's the same thing which happens here:
a match { case Name(n) => ... }
Right. It makes sense. I was half expecting this to work,
scala> val x*x = 16
<console>:21: error: not found: value *
val x*x = 16
^
scala>
but then, now I know!.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Either ways, this is very interesting. I noticed this is possible and got excited!.