progs/lecture2.scala
changeset 51 0e60e6c24b99
parent 39 c6fe374a5fca
child 53 9f8751912560
--- a/progs/lecture2.scala	Wed Nov 16 14:37:18 2016 +0000
+++ b/progs/lecture2.scala	Wed Nov 16 15:05:40 2016 +0000
@@ -1,3 +1,20 @@
+// Scala Lecture 2
+//=================
+
+
+// Option type
+//=============
+val lst = List(None, Some(1), Some(2), None, Some(3))
+
+lst.flatten
+Some(1).get
+
+val ps = List((3, 0), (3, 2), (4, 2), (2, 0), (1, 0), (1, 1))
+
+for ((x, y) <- ps) yield {
+  if (y == 0) None else Some(x / y)
+}
+
 // sudoku
 // some none
 // pattern matching