scala的reduceRight操作?

怎樣理解如下的結果?

scala> val list = List(1,2,3,4,5)

scala> list.reduceRight(_ - _)

res26: Int = 3


執行過程如下:

(1 - ( 2 - ( 3 - ( 4 - 5 ))))


官方文檔說明:

op(x_1, op(x_2, ..., op(x_{n-1}, x_n)...))

where x1, ..., xn are the elements of this mutable indexed sequence.


文檔地址:

https://www.scala-lang.org/api/current/scala/Array.html#reduceRight[B>:A](op:(A,B)=>B):B

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章