equal
deleted
inserted
replaced
|
1 |
|
2 package Main |
|
3 |
|
4 object ComprehensionsTest extends App { |
|
5 def even(from: Int, to: Int): List[Int] = |
|
6 for (i <- List.range(from, to) if i % 2 == 0) yield i |
|
7 |
|
8 Console.println(even(0, 20)) |
|
9 } |
|
10 |
|
11 object ComprehensionsTest2 extends App { |
|
12 def foo(n: Int, v: Int) = |
|
13 for ( |
|
14 i <- 0 until n; |
|
15 j <- i + 1 until n if i + j == v |
|
16 ) yield Pair(i, j); |
|
17 |
|
18 foo(20, 32) foreach { |
|
19 case (i, j) => |
|
20 println("(" + i + "," + j + ")") |
|
21 } |
|
22 } |
|
23 |
|
24 object ComprehensionTest3 extends App { |
|
25 for ( |
|
26 i <- Iterator.range(0, 20); |
|
27 j <- Iterator.range(i + 1, 20) if i + j == 32 |
|
28 ) println("(" + i + ", " + j + ")") |
|
29 } |