Scala深入浅出实战经典:20,Scala中的本地函数与作为语言一等公民的函数详解

object FunctionOps {
    def main(args: Array[String]){
        val width = args(0).toInt
        for(arg <- args(1))
          processData(arg.toString(),width)

    }


    def processData(filename:String,width:Int){
        //本地函数,也叫内部函数
        def processLine(line:String){
            if(line.length() > width)
                println(filename + ": " + line)
        }

        val source = Source.fromFile(filename)
        for(line <- source.getLines)
          processLine(line)

    }
}

你可能感兴趣的:(scala)