summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGeorge Petrov <petrovg@gmail.com>2013-07-29 13:53:55 +0100
committerGeorge Petrov <petrovg@gmail.com>2013-07-29 13:53:55 +0100
commit04e50a75fa253f71cf5de0f45d423f06dd9933d2 (patch)
tree0a0559e678f10b7ba7a33ae175f750d6aee2393c
parent7673ae8a6dc79fdc8f555d8e0c64834af17403d1 (diff)
Added for comprehensions and conditionals
-rw-r--r--scala.html.markdown48
1 files changed, 47 insertions, 1 deletions
diff --git a/scala.html.markdown b/scala.html.markdown
index 82bf9db2..783c7ae6 100644
--- a/scala.html.markdown
+++ b/scala.html.markdown
@@ -63,4 +63,50 @@ a(21) // Throws an exception
val m = Map("fork" -> "tenedor", "spoon" -> "cuchara", "knife" -> "cuchillo")
m("fork")
m("spoon")
-m("bottle") // Throws an exception \ No newline at end of file
+m("bottle") // Throws an exception
+
+val safeM = m.withDefaultValue("no lo se")
+safeM("bottle")
+
+val s = Set(1, 3, 7)
+s(0)
+s(1)
+
+
+// Tuples
+
+
+// Combinators
+
+s.map(sq)
+
+val sSquared = s. map(sq)
+
+sSquared.filter(_ < 10)
+
+sSquared.reduce (_+_)
+
+
+// For comprehensions
+
+for { n <- s } yield sq(n)
+
+val nSquared2 = for { n <- s } yield sq(n)
+
+for { n <- nSquared2 if n < 10 } yield n
+
+for { n <- s; nSquared = n * n if nSquared < 10} yield nSquared
+
+
+
+// Conditionals
+
+val x = 10
+
+if (x == 1) println("yeah")
+if (x == 10) println("yeah")
+if (x == 11) println("yeah")
+
+
+// Object oriented features
+