Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Scalaのイテラブルから関数引数を渡すことは可能ですか?
val arguments= List(1,2) def mysum(a:Int,b:Int)={a+b}
リストの内容を引数として使用して mysum を呼び出すにはどうすればよいでしょうか?
mysumリストで機能するには、関数を「varargs」に対応させる必要があります。
mysum
scala> def mysum ( args : Int* ) = args.sum mysum: (args: Int*)Int scala> val arguments = List(1,2) arguments: List[Int] = List(1, 2) scala> mysum(arguments: _*) res0: Int = 3