etc) • Scala is opinionated (For comps, Unit, Option) • Scala is “Magic” (apply, smart: set vs class) • Why? • Because it tries to push us in the right direction • Functional Programming
no problem val result= for (i <- List(1,2,3); j <- List(4,5,6)) yield (i,j) println(result) // List((1,4), (1,5), (1,6), (2,4), (2,5), (2,6), (3,4), (3,5), (3,6)) PART 5
constraints - no problem val result= for (i <- List(1,2,3) if i % 2 != 0; j <- List(4,5,6) if j % 2 == 0) yield(i,j) println(result) // List((1,4), (1,6), (3,4), (3,6)) PART 6
deep into functional writing • Easy to “comprehend” it as opposed to for big blocks • Keep your bugs contained in the transformations • Easier to test - data goes through the pipeline PART 8
classOption[+A] extends Product with Serializable • WHY? NULL was a bad idea & error prone • Scala solution of how to represent “maybe” (something or nothing) • Represents optional values. Instances of Option are either an instance of scala.Some or the object None. final case classSome[+A](value: A) extends Option[A] with Product with Serializable Object None extends Option[Nothing] with Product with Serializable • Not to be confused with Nothing: abstract final classNothing extends Any PART 1
makes calling functions on sequences easier and more intuitive. - They can very helpful: val m = t match { case x if 0 until 10 contains x => true case _ => false } PART 4