I have a library class which I can't change:
class MultiPart {
private val _parts: Seq[Part] = Seq.empty[Part])
def addHead(head: Head): MultiPart = Multipart(_parts :+ head)
def addPart(part: Part): MultiPart = Multipart(_parts :+ part)
}
In my code, I want to construct an immutable object of class Multipart, while iterating in a for loop. But I am not able to figure out how to do that. My current code looks like :
var mp: MultiPart = new MultiPart().addHead(head)
arrParts.foreach(x => mp.addPart(x))
Is there a way to fix this?
foldLeft/foldRight.MultiPartwith newSeq[Part]?