Can I destroy the (sample picture) Scala list in a reusable var?

I have a list of Scala. I can destroy the list into some variables this way:

var a :: b :: tail = myList
a should be ("A1")
b should be ("B1")
tail should be ('empty)

However, it seems that I cannot reuse the same variables for another destructuring:

a :: b :: tail = anotherList
a should be ("A2")
b should be ("B2")
tail should be ('empty)

The compiler tells me that he expected a half-colony, but found an equal sign. Why is this? Is it impossible to use already declared variables during destruction? Am I doing something stupid?

+4
source share
1 answer

To retrieve a template, a prefix is ​​required case, valor varor must occur in the expression for. Therefore, resetting variables is not possible.


Scala Β§Β§ 4.1 (), 4.2 (), 6.19 ( ) 8.4 ( )

+4

Source: https://habr.com/ru/post/1536594/


All Articles