scala匿名函数

package com.ming.test
import scala.math._ object AnonymousFunc { def valueAtOneQuarter(f:(Double)=>Double)=f(0.25) def mulby(factor:Double)=(x:Double,y:Double)=>factor*x*y def main(args: Array[String]): Unit = { var a=Array(3.14,2,3).map { (x:Double) => 3*x }
for(i<-a)println(i)
var b=valueAtOneQuarter(ceil _)
println(b) var c=mulby(4)
var d=c(4,5)
println(d) //高阶函数的使用,打印一个三角形
(1 to 9).map("*" * _).foreach {println } (1 to 9).filter(_ % 2==0).foreach { println} //对字符串进行排序哦
"mdasfsda,sdafdsaf,saf,哈哈发生大幅".split(",").sortWith(_.length>_.length).foreach { println } aa() } //控制抽象
def until(condition: => Boolean)(block: =>Unit){
if(!condition){
block
until(condition)(block)
}
} def aa()={
var x=10
until (x==0){
x-=1
println(x)
}
} }
上一篇:在VPS上搭建SS访问火星


下一篇:理解squid的正向和反向代理