Scala multiple assignment to existing variable -
I can do something
def: Long] = ... val (a, b) = f ()
What about the variable already exists? I am running a set of data above the filter and I do not want to chain them (long names and such). This is what I tried, but it complains of hope; Instead of on the last line:
var a = ... initialization for this data var b = ... some other init (a, b) = g (a, b) / / Error: Expected ';' But got '='
Is there any way to avoid intermediary tubal?
As Alex said, there is no short answer. What is happening with your code is this: When a and b are already bound in the current scope, (a, b) "Take the values of A and B and prepare a tuple from them."
Therefore,
(a, b) = ...
< Is the equivalent of / pre>
(new tubal 2 (a, b)) = ...
which is not explicitly What you want (besides this is being unnecessary).
The syntax you want (the ability to assign multiple variables at once) is simply not in existence. You can not assign same value to the already existing variable at a time (the usual syntax "A = B = ..." which is found in many other languages, does not work in Scala. ) I do not think that it is an accident that gets preferential treatment at Wal; They are almost always a better idea.
It seems that all these things are being taken in some kind of loop, and do repeating tasks. It is not very idiotic, Scala. I suggest that you try to eliminate the use of the Vars in your program and work in a more functional way by using the choice of maps, flatmaps, filters, panels, etc.
Comments
Post a Comment