How can I loop though a set and reassign every item in collection with new value?
scala
Solution
If you insist on mutability you can go with something like this:
var followingIds = Set("foo", "bar")
followingIds = followingIds.map(e => new ObjectId(e))
But you can make your code more scalish with immutable things:
val followingIds = Set("foo", "bar")
val objectIds = followingIds.map(e => new ObjectId(e))
Now variables (values) names are pretty descriptive
Problem
Hi I want to loop a set of Strings and convert them from String type to ObjectId type. I tried this way: ``` followingIds.foreach(e => e = new ObjectId(e)) ``` But I cant do that assignement. I also tried using "for" but I don't know how to access each position of the Set by Index. ``` for (i <- 0 until following.size) { following[i] = new ObjectId(following[i]) } ``` This neither work, Can anyone help me?!? Please!