Skip to content

Instantly share code, notes, and snippets.

@oreillyross
Last active August 29, 2015 14:07
Show Gist options
  • Save oreillyross/4bd9bb0e18801734a257 to your computer and use it in GitHub Desktop.
Save oreillyross/4bd9bb0e18801734a257 to your computer and use it in GitHub Desktop.
Scala Collections

Vectors are created analogously to Lists

val nums = New Vector(1,2,56,-87)

instead of List cons operator x :: xs use x +: xs or xs:+ x

Seq is a base class of List and Vector

Seq itself is a sub class of Iterable

Seq - Set - Map all sub class of Iterable

One can also use Range

val r: Range = 1 until 5 // 1,2,3,4 val s: Range = 1 to 5 // 1,2,3,4,5 1 to 10 by 3 // 1,4,7,10

Stream

x #:: xs == Stream.cons(x,xs)

Tail is only evaluated when it is needed, but same as lists

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment