# HG changeset patch # User Christian Urban # Date 1520856710 0 # Node ID 3141278cfc526712b7b1d3658544b158232ca486 # Parent e380f5cf27f1133b939b2f86fb007ac698321d80 updated diff -r e380f5cf27f1 -r 3141278cfc52 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 //========================