Created
April 28, 2012 06:18
-
-
Save pminkov/2516506 to your computer and use it in GitHub Desktop.
Scala scope
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Return the square of all positive numbers in x | |
* which are also present in y. | |
*/ | |
def f(x: List[Int], y: List[Int]): List[Int] = { | |
val filtered = { | |
val iny = x.filter(v => y.contains(v)) | |
val pos = iny.filter(_ > 0) | |
pos | |
} | |
// iny.map(x => x * x) <- Won't compile. | |
filtered.map(x => x * x) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment