Skip to content

Instantly share code, notes, and snippets.

@pminkov
Created April 28, 2012 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pminkov/2516506 to your computer and use it in GitHub Desktop.
Save pminkov/2516506 to your computer and use it in GitHub Desktop.
Scala scope
/** 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