1. 程式人生 > >scala的reduceRight操作?

scala的reduceRight操作?

scala

怎樣理解如下的結果?

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

本文出自 “6427382” 博客,請務必保留此出處http://6437382.blog.51cto.com/6427382/1953096

scala的reduceRight操作?