白乔专栏

资深感性程序员,大数据爱好者,中国科学院博士

scala学习笔记:变量声明中的模式

先看个正常的写法:scala> val x = 1 x: Int = 1体会一下元组的写法:scala> val (x,y,z)=(1,2,3) x: Int = 1 y: Int = 2 z: Int = 3再来体会一个Array的匹配:scala> val Array(x,y...

2015-02-28 17:49:05

阅读数:2655

评论数:0

scala学习笔记:理解并行集合par

scala> (1 to 5).foreach(println(_)) 1 2 3 4 5scala> (1 to 5).par.foreach(println(_)) 1 2 3 4 5以下代码获取到参与并行计算的线程:scala> (0 to 10000).collect{c...

2015-02-28 17:00:40

阅读数:5283

评论数:0

快速了解Scala技术栈

http://www.infoq.com/cn/articles/scala-technology/我无可救药地成为了Scala的超级粉丝。在我使用Scala开发项目以及编写框架后,它就仿佛凝聚成为一个巨大的黑洞,吸引力使我不得不飞向它,以至于开始背离Java。固然Java 8为Java阵营增添了...

2015-02-28 16:13:53

阅读数:2289

评论数:0

scala学习笔记:控制抽象

def repeat(n:Int)(action: =>Unit)=for(i<-1 to n)actionvar i = 0 repeat(5){ println(i=i+1) }另外一个例子:scala> def until(condition: =>Boolean)(...

2015-02-28 15:25:30

阅读数:1430

评论数:0

scala中的call-by-name和call-by-value

http://www.jianshu.com/p/93eefcb61d4fval和def的区别在scala中,可以用val和def前缀来定义变量,例如: val x = 1 def y = “foo”这两者的区别在于:val定义值时,会做call-by-value操作,def则会做call-...

2015-02-27 13:16:27

阅读数:2824

评论数:0

scala学习笔记:各种奇怪的写法

Unit函数的定义: def foo()={println("hi")} 等号可以省略: def foo(){println("hi")} update方法: x(y) = z 相当于: x.update(y, z) 单参数方法的调用: xOb...

2015-02-26 22:01:27

阅读数:1204

评论数:0

scala学习笔记:match与unapply()

编写如下代码:object MatchTest { def foo(a : Any) : String = { a match { case 1 => "int:1" ...

2015-02-26 14:09:21

阅读数:3046

评论数:0

scala学习笔记:无参函数

scala> def repeat(times:Int)(run:()=>Unit)=for(i<-1 to times)run() repeat: (times: Int)(run: () => Unit)Unitscala> repeat(2){println(&...

2015-02-12 17:50:10

阅读数:1227

评论数:0

scala学习笔记:函数与方法

http://stackoverflow.com/questions/2529184/difference-between-method-and-function-in-scalaA Function Type is (roughly) a type of the form (T1, ..., T...

2015-02-12 17:31:05

阅读数:682

评论数:0

scala学习笔记:理解函数

定义一个函数:scala> def foo(x:Int)=x*2 foo: (x: Int)Int这个函数的类型是Int=>Int:scala> var bar = foo _ bar: Int => Int = <function1>scala> var...

2015-02-12 11:20:43

阅读数:579

评论数:0

scala学习笔记:理解类继承

scala> import scala.reflect._ import scala.reflect._scala> class Person(@BeanProperty var name: String, val gender: Boolean=true){} defined cla...

2015-02-09 20:55:49

阅读数:598

评论数:0

scala学习笔记:理解lazy值

scala> var counter = 0 counter: Int = 0scala> def foo = {counter = 1; counter} foo: Intscala> val value1 = foo; lazy val value2 = foo; def ...

2015-02-08 18:44:50

阅读数:1716

评论数:0

scala学习笔记:match表达式

写了一个超级长的表达式,估计不是最简洁的:scala> def foo(ch:Any)=ch match { case true=>"male";case false=>"female";case i:Int if(i==0)=>&q...

2015-02-06 21:30:00

阅读数:916

评论数:0

scala学习笔记:集合

scala> 1 to 10 res9: scala.collection.immutable.Range.Inclusive = Range(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)scala> List(1,2,3,4) res10: List[Int] = L...

2015-02-06 08:47:41

阅读数:719

评论数:0

scala学习笔记:高阶函数

scala> def power(y:Double)=(x:Double)=>Math.pow(x,y) warning: there were 1 deprecation warnings; re-run with -deprecation for details power: (y...

2015-02-06 08:37:12

阅读数:1148

评论数:0

提示
确定要删除当前文章?
取消 删除