-
-
Save mbektimirov/2660553 to your computer and use it in GitHub Desktop.
Simple scala collection examples
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
scala> (1 to 20).toList | |
res1: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20) | |
//Simple side effects | |
scala> res1 take 3 foreach (i => println(i)) | |
1 | |
2 | |
3 | |
scala> res1 take 3 foreach println | |
1 | |
2 | |
3 | |
//String representation | |
scala> (res1 take 3).toString | |
res9: String = List(1, 2, 3) | |
scala> (res1 take 3).mkString | |
res10: String = 123 | |
scala> (res1 take 3).mkString(", ") | |
res11: String = 1, 2, 3 | |
scala> (res1 take 3).mkString("[", ", ", "]") | |
res12: String = [1, 2, 3] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment