Slide 10
Slide 10 text
メソッドの関数としての利用
Scala
ではメソッド名そのままで関数オブジェクト
として参照できる(ref. )
/* Scala */
scala> def factorial(n: Long): Long = (1L to n).product
def factorial(n: Long): Long
scala> (0L to 9L).map(factorial)
val res0: IndexedSeq[Long] = Vector(1, 1, 2, 6, 24, 120, 720,
5040, 40320, 362880)
/* Kotlin */
>>> fun factorial(n: Long): Long = (1L..n).fold(1L) { acc, x
-> acc * x}
>>> (0L..9L).map(::factorial)
res1: kotlin.collections.List = [1, 1, 2, 6, 24,
120, 720, 5040, 40320, 362880]
eta-expansion
10