user16367669 Asks: What is the most efficient way to transform of seq of X to a seq of Y
I have a
I have a
Seq
of objects like Seq(x1, x2, x3, x4)
and I want to tranform it to Seq(y1, y2, y3, y4)
What is the most efficient way of doing so
Right now I am
Code:
val seq1 = Seq(x1, x2, x3......)
var seq2 = Seq[MyType2]()
for (myObj <- seq1) {
seq2 = seq2 :+ myObj.tranformToType2
}
The problem is that the scala doc says
Scala Standard Library 2.12.15 – scala.collection.Seq
a new sequence consisting of all elements of this sequence followed by elem.
so I was wondering what is the most idiomatic/efficient way of tranforming a list of object to another list of object
Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Top Site Forum.