summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-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
+