Slide 5
Slide 5 text
FUNCTIONAL In Scala everything returns a value
scala> val myInt = 1
myInt: Int = 1
scala> def myFunction = "I don't need a return"
myFunction: String
scala> val result = for (n <- 0 to 10) yield n
result: scala.collection.immutable.IndexedSeq[Int] = Vector(0, 1, 2, 3, 4, 5, 6, 7, 8,
9, 10)
scala> val ifAreValues2 = if (true) "test"
ifAreValues2: Any = test
scala> val ifAreValues3 = if (true) "test" else "test2"
ifAreValues3: String = test
Functional style encourages to pipe the
results of functions and operations Vs
Imperative style
Iterator.continually(Option(queue.poll(1, TimeUnit.SECONDS))).takeWhile(_ => running)
foreach { msg => write(msg) }