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

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -