val list=List(1,2,3,4)
list.reduce((x:Int,y:Int)=>x+y)--->list.reduceLeft((x:Int,y:Int)=>x+y)

var first = true
var acc:Int = 0
op=(x:Int,y:Int)=>x+y

for循环
第一次循环:acc=1 first = false
第二次循环:acc=op(1,2)=1+2=3
第三次循环:acc=op(3,3)=3+3=6
第四次循环:acc=op(6,4)=6+4=10
======================================================================
val list=List(1,2,3,4)
list.reduceRight((x:Int,y:Int)=>x-y)

op(head, tail.reduceRight(op))---》op(1,List(2,3,4).reduceRight(op)---->op(2,List(3,4).reduceRight(op)-->op(3,List(4).reduceRight(op)=4)=3-4=-1)=2-(-1)=3)=1-3=-2

========================================================================
val list=List(1,2,3,4)
list.foldRight(0)(_-_) --->reverse.foldLeft(z)((right, left) => op(left, right))

List(4,3,2,1).foldLeft(z)((right, left) => op(left, right))

var acc = 0
var these = List(4,3,2,1)
while (!these.isEmpty) {
acc = op(acc, these.head)
these = these.tail
}

while循环
第一次while: acc=op(0,4)=>op(4,0)=4-0=4 these=List(3,2,1)
第二次while: acc=op(4,3)=>op(3,4)=3-4=-1 these=List(2,1)
第三次while: acc=op(-1,2)=>op(2,-1)=2-(-1)=3 these=List(1)
第四次while: acc=op(3,1)=>op(1,3)=1-3=-2 these=List()

=========================================================================
val array=Array(1,2,3,4)------>其本质是调用了Array这个object的apply方法

def apply(x: Int, xs: Int*): Array[Int] = {
//构建了一个跟目标数组长度一致的空的数组
val array = new Array[Int](xs.length + 1)
//把参数中的第一个元素赋值给空的数组的0下标
array(0) = x
var i = 1
for (x <- xs.iterator) { array(i) = x; i += 1 }
// array(1)=2 i=2
// array(2)=3 i=3
// array(3)=4 i=4
array--->Array(1,2,3,4)
}

import scala.collection.mutable._
Array(1,2,3,4).map(_+_)

import scala.collection.mutable.A
import scala.collection.mutable.B
import scala.collection.mutable.C
import scala.collection.mutable.D

最新文章

  1. javascript学习之BOM
  2. GreenDao2.2升级GreenDao3.0的适配之路
  3. UIActivityViewController 系统社交化 共享
  4. iOS,监听tableVIew的偏移量
  5. 5.开发webservice
  6. CSS 禁止浏览器滚动条的方法(转)
  7. bootStrap-1
  8. easyui获取一行数据和修改data-options的值
  9. 《学习OpenCV》 第四章 习题六
  10. 对比Windows 8模拟器(Simulator)和Windows Phone仿真器(Emulator)
  11. Egret 学习之 从HelloWorld项目开始 (二)
  12. [HNOI 2017]抛硬币
  13. windows10环境下的RabbitMQ安装步骤(图文)
  14. Vue系列之 =&gt; html-webpack-plugin的两个基本作用
  15. IPerf——网络测试工具介绍与源码解析(3)
  16. &lt;20190104&gt;关掉一些鸡肋的Win10功能
  17. Matplotlib常用绘图示例
  18. 9.mysql-存储过程.md
  19. RAR压缩包审计工具unrar-nofree
  20. 【Spring】SpringMVC之REST编程风格

热门文章

  1. C++:打开一个文件夹下一系列的文件
  2. PHP转换oracle数据库的date类型
  3. 解决&lt;%@taglib prefix=&quot;s&quot; uri=&quot;/struts-tags&quot;%&gt;显示找不到
  4. Codeforces Round #622 (Div. 2) C1. Skyscrapers (easy version)(简单版本暴力)
  5. [1/100]Python安装
  6. 在HTML中实现两个div并排显示
  7. idea设置单行注释格式(包括配置文件)
  8. Ubuntu18 mongodb 离线安装
  9. Embedded Packet Capture (EPC)
  10. Java IO流详解(五)——缓冲流