ArrayBuffer
すべてのオブジェクトをそれぞれのサイズに変換して既存のバッファに変換したい があります。
trait Obj {
def size: Int
}
def copySizes(input: ArrayBuffer[Obj], output: ArrayBuffer[Int]): Unit = {
output.clear()
input foreach { obj =>
output += obj.size
}
}
scala で copySizes を記述するためのより良い慣用的な方法はありますか? 私は次のような構文について考えていました:
input.mapTo(_.size, output)