Skip to content

Instantly share code, notes, and snippets.

@jbrechtel
Created August 21, 2011 01:48
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 jbrechtel/1159981 to your computer and use it in GitHub Desktop.
Save jbrechtel/1159981 to your computer and use it in GitHub Desktop.
Scala collections
//creating collections of specific types
val intArray = Array(1,2,3,4)
val intLinkedList = List(4,5,6,7)
val indexedSequenceOfStrings = IndexedSeq("one", "two", "three")
//filtering items in a collection
val evens = List(1,2,3,4,5,6,7).filter(_ % 2 == 0)
//mapping
List("hi", "my", "name", "is", "slim", "shady").map(_.toUpperCase)
//slightly more involved mapping
//remove the vowels from each string
val vowels = "aeiou"
List("james", "brechtel").map { s =>
s.filterNot(vowels.contains)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment