Scala学习笔记-11

package com.leegh.oop

import scala.io.Source

/**
* @author Guohui Li
*/
object FunctionOps {

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

var increase = (x: Int) => x + 1
increase(10)
increase = (x: Int) => x + 9999

val someNumbers = List(-11, -10, 5, 0, -5, 10)
someNumbers.foreach((x: Int) => println(x))
someNumbers.filter((x: Int) => x > 0)
someNumbers.filter((x) => x > 0)
someNumbers.filter(x => x > 0)
someNumbers.filter(_ > 0)
val f = (_: Int) + (_: Int)
f(5, 10)
}

def processData(filename: String, Int) {
def processLine(line: String) { //本地函数,processLine是processData的私有函数
if (line.length > width)
println(filename + ":" + line)
}
val source = Source.fromFile(filename)
for (line <- source.getLines())
processLine(line)
}

}

附:

本博客说明:

1.整理思路,提高自己。

2.受教于王家林老师,​有所收获,故推荐。

3.博客注重实践,多余的文字就不多说了,都是做技术的。

4.信息来源于 DT大数据梦工厂微信公众账号:DT_Spark。​

DT大数据梦工厂的微信公众号是DT_Spark,每天都会有大数据实战视频发布,请您持续学习。

Scala 深入浅出实战经典(1-64讲)完整视频、PPT、代码下载:

百度云盘:http://pan.baidu.com/s/1c0noOt6
腾讯微云:http://url.cn/TnGbdC
360云盘:http://yunpan.cn/cQ4c2UALDjSKy 访问密码 45e2

原文地址:https://www.cnblogs.com/leegh1992/p/4703228.html