learning scala PartialFunction】的更多相关文章

Partial函数的定义 scala> val isVeryTasty: PartialFunction[String, String] = { case "Glazed Donut" | "Strawberry Donut" => "Very Tasty"}isVeryTasty: PartialFunction[String,String] = <function1> scala> isVeryTasty(&qu…
1.orElse和andThen的区别 源码如下,区别很明显,orElse是并列的关系,而andThen是调用者的结果作为k的输入. trait PartialFunction[-A, +B] extends (A => B) { ......} def orElse[A1 <: A, B1 >: B](that: PartialFunction[A1, B1]): PartialFunction[A1, B1] = new OrElse[A1, B1] (this, that) ove…
数组:可变的,可索引的,元素具有相同类型的数据集合 一维数组 scala> val intValueArr = new Array[Int](3)intValueArr: Array[Int] = Array(0, 0, 0) scala> val myStrArr = Array("BigData","hadoop","spark")myStrArr: Array[String] = Array(BigData, hadoop, s…
1 .if satement 与其它语言不同的是,scala if statement 返回的是一个值 scala> val a = if ( 6 > 0 ) 1 else -1a: Int = 1 2. while statement 3. do.. while statement 4 for statement for ( 变量 <-  表达式 ) { 语句块}: scala> for ( i <- 1 to 3 ) println(i)123 scala> for…
scala读文件:   example: scala> import scala.io.Sourceimport scala.io.Source scala> var inputFile = Source.fromFile("text.txt")inputFile: scala.io.BufferedSource = non-empty iterator scala> for ( line <- inputFile.getLines()) println(lin…
scala 写文件功能: scala> import java.io.PrintWriterimport java.io.PrintWriter scala> val outputFile = new PrintWriter("text.txt")outputFile: java.io.PrintWriter = java.io.PrintWriter@213c812a scala> outputFile.println("hello panzidong&q…
控制台输出语句: print println example: scala> print("i=");print(i)i=345scala> println("hello ");println("world")hello world…
控制台输入语句: readInt, readDouble, readByte, readShort, readLong, readChar, readBoolean, readLine example:scala> import io.StdIn._import io.StdIn._ scala> var i=readInt()2i: Int = 2 scala> var f=readFloat()2.2f: Float = 2.2 scala> var b=readBoolean…
scala 变量: val : 声明时,必须被初始化,不能再重新赋值. scala> test = "only1"<console>:11: error: not found: value test test = "only1" ^<console>:12: error: not found: value test val $ires0 = test ^    var :可被多次赋值. scala> var test2 = &qu…
scala 操作符: 算术运算符:  +  - *  / % 关系统运算符: > , < ,= ,!= ,>=,<=, 逻辑运算符: && . || , ! 位运算符:&, |, ^,~,<<,>>,>>>(无符号右移) 赋值运算符: = 优先及由上及下…