Scala
文章平均质量分 59
GeekStuff
I will be posting instruction guides, how-tos, troubleshooting tips.
展开
-
=>在Scala中意义
=> has several meanings in Scala, all related to its mathematical meaning as implication.1. In a value, it introduces a function literal, or lambda. e.g. the bit inside the curly braces inList原创 2015-03-04 11:15:56 · 1445 阅读 · 3 评论 -
Scala闭包
闭包(Closure)是引用了自由变量的函数,它的返回值依赖于这个函数外部的一个或者多个变量。闭包本身类,它的特点是它所创建的对象实例可以引用外部函数/类里面的变量。 即闭包就是能够读取外部函数的内部变量的函数。原创 2015-01-13 18:13:24 · 1406 阅读 · 0 评论 -
scala中val function
示例val add1 = (i: Int) => i + 1 // implicit return type (IRT)val add1: Int => Int = (i) => i + 1 // explicit return type (ERT)方法体加入括号val add1 = (i: Int) => { i + 1 }val add1: Int => Int =原创 2016-05-22 14:31:42 · 1061 阅读 · 0 评论 -
Scala 类型参数的界定
trait Similar { def isSimilar(x: Any): Boolean}case class MyInt(x: Int) extends Similar { def isSimilar(m: Any): Boolean = m.isInstanceOf[MyInt] && m.asInstanceOf[MyInt].x == x}原创 2015-03-04 10:44:52 · 1996 阅读 · 0 评论 -
Scala类继承和特质
类继承class Point(val xc: Int, val yc: Int) { var x: Int = xc var y: Int = yc def move(dx: Int, dy: Int) { x = x + dx y = y + dy println ("Point x location : " + x);原创 2015-01-14 12:56:26 · 1680 阅读 · 0 评论 -
Scala数组使用
1 数组的声明使用数组时,必须声明一个变量来引用数组,同时确定数组变量的类型,如以下语法:var z:Array[String] = new Array[String](3)orvar z = new Array[String](3)用如下方式赋值:z(0) = "Zara"; z(1) = "Nuha"; z(4/2) = "Ayan"原创 2015-01-13 19:58:45 · 1808 阅读 · 0 评论 -
Scala集合
List在Scala中,List和数组非常相似,所有的元素都有相同的类型,但是有两个重要的不同之处:(1)List是不可变的,不能通过赋值改变其元素的值;(2)List是链式结构,而数组是平坦的线性结构。List的定义// List of Stringsval fruit: List[String] = List("apples", "oranges", "pear原创 2015-01-14 12:54:01 · 902 阅读 · 0 评论 -
Scala List foldLeft用法
def sum(list: List[Int]): Int = list.foldLeft(0)((r,c) => r+c)def sum(list: List[Int]): Int = list.foldLeft(0)(_+_)def product(list: List[Int]): Int = list.foldLeft(1)(_*_)def count(list: List[Any]):原创 2015-03-13 18:48:09 · 1897 阅读 · 0 评论 -
Spark RDD
数据抽象RDD定义:RDD是只读的、分区记录集合。 特点:支持工作集、自动容错、位置感知、可伸缩; 5个属性: 1. 一组分片(Partition):每个分片逻辑上被映射成Block,会被一个计算任务处理。RDD默认分片个数为程序分配到的CPU核数; 2. 一个分片计算函数:每个RDD都会实现compute函数; 3. 依赖关系:RDD之间转换形成前后依赖关系,当部分分区数据丢失时,原创 2016-04-24 13:30:41 · 1044 阅读 · 0 评论