val scores=Map("Alice"->10,"Bob"->3,"Cindy"->8) // 获取所有的key val nameList=scores.map(_._1) // map 函数返回List println(nameList.getClass) 遍历list中的元素 nameList.foreach((x:String)=>print(x+" ")) 输出 :Alice Bob Ci
在函数式语言中,函数作为一等公民,可以在任何地方定义,在函数内或函数外,可以作为函数的参数和返回值,可以对函数进行组合.由于命令式编程语言也可以通过类似函数指针的方式来实现高阶函数,函数式的最主要的好处主要是不可变性带来的.没有可变的状态,函数就是引用透明(Referential transparency)的和没有副作用(No Side Effect). 任何一种函数式语言中,都有map函数与faltMap这两个函数,比如Python虽然不是纯函数式语言,也有这两个函数.再比如在jdk1.8之后
Job类 /** * Define the comparator that controls * how the keys are sorted before they * are passed to the {@link Reducer}. * @param cls the raw comparator * @see #setCombinerKeyGroupingComparatorClass(Class) */ publicvoid setSortCompar