scala 入门

import scala.reflect.Class

/**
 * Created by spark on 15-2-15.
 */
object ArrayTest {
  def main(args: Array[String]) = {
    println(arr.map(x=>(2*x)));//map括号里是个没函数名的函数  
     println(arr.filter(_%2==1).map(2*_));
    println(arr.map(_->1));
    println(trible(14));
    println(half(14));
    println(9::List(4,2));

  }
  val arr = List(0, 1, 2, 3, 4, 5);
  def mulBy(factor:Double) = (x:Double) => factor * x
  val trible = mulBy(3);
  val half = mulBy(0.5);
}




将打印出


List(0, 2, 4, 6, 8, 10)
List(2, 6, 10)
List((0,1), (1,1), (2,1), (3,1), (4,1), (5,1))
42.0
7.0
List(9, 4, 2)

你可能感兴趣的:(scala 入门)