Scala Tuple Deconstruction?

Unfortunately, you cannot do multiple assignments in Scala. But you may use tuples, if they fit your problem: scala> var xy = (1,2) xy: (Int, Int) = (1,2) scala> xy = (xy. _1 + xy.

_2, xy. _2 - xy. _1) xy: (Int, Int) = (3,1) This way xy is one tuple with two values.

The first value can be accessed using xy. _1 the second one using xy. _2.

Unfortunately, you cannot do multiple assignments in Scala. But you may use tuples, if they fit your problem: scala> var xy = (1,2) xy: (Int, Int) = (1,2) scala> xy = (xy. _1 + xy.

_2, xy. _2 - xy. _1) xy: (Int, Int) = (3,1) This way, xy is one tuple with two values.

The first value can be accessed using xy. _1, the second one using xy. _2.

Scala has 2 types of variables: vals and vars. Vals are similar to Java's final variables, so as far as I understand from what you're asking, the only way to assign new values in parallel to vals is by: scala> val (x, y) = (1, 2); or scala> val s = (3, 4); s: (Int, Int) = (3,4) scala> s. _1 res1: Int = 3 scala> s.

_2 res2: Int = 4.

I understand why you can't assign a new value to a val. I am talking about parallel assignment of vars. In the code from my question, x and y are both vars.

– dbyrne May 5 '10 at 21:02 He's asking if you can do val (x,y) = (1,2) and var (x,y) = (1,2) then why can't you do var x; var y; (x,y) = (1,2)? – Ken Bloom May 6 '10 at 3:40.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions