--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Fahad/CodeSamples/SequenceComprehensions.scala Sun Nov 09 19:25:10 2014 +0000
@@ -0,0 +1,29 @@
+
+package Main
+
+object ComprehensionsTest extends App {
+ def even(from: Int, to: Int): List[Int] =
+ for (i <- List.range(from, to) if i % 2 == 0) yield i
+
+ Console.println(even(0, 20))
+}
+
+object ComprehensionsTest2 extends App {
+ def foo(n: Int, v: Int) =
+ for (
+ i <- 0 until n;
+ j <- i + 1 until n if i + j == v
+ ) yield Pair(i, j);
+
+ foo(20, 32) foreach {
+ case (i, j) =>
+ println("(" + i + "," + j + ")")
+ }
+}
+
+object ComprehensionTest3 extends App {
+ for (
+ i <- Iterator.range(0, 20);
+ j <- Iterator.range(i + 1, 20) if i + j == 32
+ ) println("(" + i + ", " + j + ")")
+}
\ No newline at end of file