Skip to content

Instantly share code, notes, and snippets.

@mbektimirov
Forked from oxbowlakes/gist:1869377
Created May 11, 2012 15:47
Show Gist options
  • Save mbektimirov/2660553 to your computer and use it in GitHub Desktop.
Save mbektimirov/2660553 to your computer and use it in GitHub Desktop.
Simple scala collection examples
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