Skip to content

Instantly share code, notes, and snippets.

@cgopalan
Created October 6, 2011 02:59
Show Gist options
  • Select an option

  • Save cgopalan/1266383 to your computer and use it in GitHub Desktop.

Select an option

Save cgopalan/1266383 to your computer and use it in GitHub Desktop.
Scala Map function
object ListMap {
def squareList(xs: List[Int]): List[Int] = xs match {
case List() => xs
case y :: ys => y * y :: squareList(ys)
}
def squareListMap(xs: List[Int]): List[Int] =
xs map (x => x * x)
def main(args: Array[String]) {
println("squarelist for square of (9,13,21) returns : " + squareList(List(9, 13, 21)));
println("squareListMap for square of (9,13,21) returns : " + squareList(List(9, 13, 21)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment