Reputation: 39
I have the following sequence where I am updating every element of the pair by adding 1 by using a for-loop:
points: Seq[Point] = Seq((ax,ay), (bx,by), (cx,cy))
for (point <- points)
{
val update = Point(point.x + 1, point.y + 1)
}
However, I want to use the map method to update my elements in the following way:
val update = points.map(x => (x._1 + 1, x._2 + 1))
But it's showing me the following error:
So how can I then update my sequence using Scala map method and get rid of this error?
Upvotes: 0
Views: 488
Reputation: 1724
I think you should write:
val update: Seq[Point] = points.map(point => Point(point.x + 1, point.y + 1))
As you done in the foor loop.
Upvotes: 2