progs/comb1.scala
changeset 467 b5ec11e89768
parent 462 fb5e1ef58049
child 470 8df654e9eb4e
--- a/progs/comb1.scala	Mon Oct 24 14:46:47 2016 +0100
+++ b/progs/comb1.scala	Sat Oct 29 21:45:44 2016 +0100
@@ -156,3 +156,41 @@
 (One ~ One ~ One ~ One).parse("1111")
 
 (One || Two).parse("111")
+
+
+for (x <- List(1, 2, 3, 4)) println(x)
+for (x <- List(1, 2, 3, 4); if (2 < x)) yield (x.toString + x.toString)
+for (x <- List("2", "1", "3", "4", "1")) yield (x + x + x)
+
+(1, "one", '1')._3
+for ((x, y) <- List((1, "one"), (2, "two"), (3, "three"), (4,"many")); if (y == "many"))
+  yield (x.toString + y)
+
+
+def square(n: Int) = {
+  n * n
+}
+
+square(4 + 3 + 5)
+
+def bar(): Int = {
+  bar()
+  3
+}
+
+
+def foo(n: => Int) = {
+  print("finished")
+}
+
+foo(bar())
+
+square(12) + square(10)
+
+
+def time_needed[T](i: Int, code: => T) = {
+  val start = System.nanoTime()
+  for (j <- 1 to i) code
+  val end = System.nanoTime()
+  (end - start)/(i * 1.0e9)
+}