This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object flatMapTest { | |
| import scala.util.{ Try, Success, Failure } | |
| println("Welcome to the Scala worksheet") //> Welcome to the Scala worksheet | |
| val intList = 1 :: 2 :: 5 :: Nil //> intList : List[Int] = List(1, 2, 5) | |
| intList.map(x => x * 2) //> res0: List[Int] = List(2, 4, 10) | |
| //intList.flatMap(x=>x*2) //type mismatch; found : Int required: scala.collection.GenTraversableOnce[?] | |
| intList.foldLeft(0)((x, y) => x + y) //> res1: Int = 8 | |
| val stringList = "eins" :: "zwei" :: "drei" :: Nil |
NewerOlder