Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert immutable Seq to mutable seq with until loop

I'm trying to return a mutable Sequence with an until loop, but i have an immutable seq in return of (0 until nbGenomes) :

 def generateRandomGenome(nbGenomes:Int): IndexedSeq[GenomeDouble]={
    return ((0 until nbGenomes toSeq).map{e => generateRandomGenome}) 
  }

Return compilation error :

found   : scala.collection.immutable.IndexedSeq[org.openmole.tools.mgo.mappedgenome.genomedouble.GenomeDouble]
 required: scala.collection.mutable.IndexedSeq[org.openmole.tools.mgo.mappedgenome.genomedouble.GenomeDouble]
    return ((0 until nbGenomes toSeq).map{e => generateRandomGenome}) 

How i can force the until loop to return an mutable seq ? Thanks scala community!

like image 362
reyman64 Avatar asked May 08 '11 13:05

reyman64


1 Answers

You can convert an immutable sequence to a mutable one by creating a new mutable sequence with the varargs constructor.

scala> val l = List(1,2,3)
l: List[Int] = List(1, 2, 3)
scala> scala.collection.mutable.ArraySeq(l:_*)
res0: scala.collection.mutable.ArraySeq[Int] = ArraySeq(1, 2, 3)
like image 177
Kim Stebel Avatar answered Oct 04 '22 03:10

Kim Stebel