为了更好的驾驭spark,最近在学习scala语言特性,主要看《快学scala》,顺便把一些自己认为有用的代码记下来。
package examples object Example12 extends App{ def mulBy1(factor:Double)=(x:Double)=>factor*x def mulBy2(factor:Double)(x:Double)=factor*x val triple = mulBy1(3) println(triple(8)) println(mulBy1(3)(8)) println(mulBy2(3)(8)) def myUntil1(myCondition: =>Boolean)(myBlock: =>Unit) { if(!myCondition) { myBlock myUntil1(myCondition)(myBlock) } } var x=10 myUntil1(x==0) { x-=1 println(x) } def myUntil2(myCondition: =>Boolean)(myBlock: ()=>Unit) { if(!myCondition) { myBlock() myUntil2(myCondition)(myBlock) } } x=10 myUntil2(x==0){()=> x-=1 println(x) } val add : Int => Int =>Int = x => y => x + y println(add(1)(2)) val add2:(Int) =>( Int =>Int )= (x) => (y => x + y) println(add2(1)(2)) }
本文作者:linger
本文链接:http://blog.csdn.net/lingerlanlan/article/details/44858225
时间: 2024-12-19 08:27:26