Created
October 6, 2011 02:59
-
-
Save cgopalan/1266383 to your computer and use it in GitHub Desktop.
Scala Map function
This file contains hidden or 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
| 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