copy - Scala build an arraybuffer of the same length with integers -


i have arraybuffer want convert objects respective size existing buffer:

trait obj {   def size: int }  def copysizes(input: arraybuffer[obj], output: arraybuffer[int]): unit = {   output.clear()   input foreach { obj =>     output += obj.size   } } 

is there better idiomatic way describe copysizes in scala ? thinking syntax like:

input.mapto(_.size, output) 

you could

output ++= input.view.map(_.size) 

which has non-negligible additional overhead (~2x runtime) more compact. can write version more compactly, though:

input.foreach{ output += _.size } 

so don't see reason not use it.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -