# HG changeset patch # User Christian Urban # Date 1520856710 0 # Node ID 2de1f79dedf0986e7d055ab4bc0f686c2c4db74f # Parent fb229ff1740947e081148acac6f7089ce237c7e2 updated diff -r fb229ff17409 -r 2de1f79dedf0 progs/lecture2.scala --- a/progs/lecture2.scala Thu Mar 08 12:33:09 2018 +0000 +++ b/progs/lecture2.scala Mon Mar 12 12:11:50 2018 +0000 @@ -178,6 +178,20 @@ // ... how are we supposed to know that this returns -1 +//other example for options...NaN +val squareRoot: PartialFunction[Double, Double] = { + case d: Double if d > 0 => Math.sqrt(d) +} + +val list: List[Double] = List(4, 16, 25, -9) + +val result = list.map(Math.sqrt) +// => result: List[Double] = List(2.0, 4.0, 5.0, NaN) + +val result = list.collect(squareRoot) +// => result: List[Double] = List(2.0, 4.0, 5.0) + + // Higher-Order Functions //========================