public
Created

Scala collections

  • Download Gist
collections.scala
Scala
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
//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)
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.