scala> //Mapping methods in List scala> scala> // map() #357, #366 scala> // Note : range() is a method available in scala> // Companion Object 'List' scala> val data = List.range(1, 5) data: List[Int] = List(1, 2, 3, 4) scala> val res = data.map(_ + 1) res: List[Int] = List(2, 3, 4, 5) scala> scala> // flatMap() scala> val data = List("This is", "an example") data: List[String] = List(This is, an example) scala> val res = data.map(_.split(" ")) res: List[Array[String]] = List(Array(This, is), Array(an, example)) scala> val res = data.flatMap(_.split(" ")) res: List[String] = List(This, is, an, example) scala> scala> //foreach() : Takes a procedure as an argument #359 scala> val data = List.range(1, 5) data: List[Int] = List(1, 2, 3, 4) scala> var sum = 0 sum: Int = 0 scala> val res = data.foreach{ x => | sum = sum + x | } scala> sum res24: Int = 10