Skip to content

Instantly share code, notes, and snippets.

@davidandrzej
Created May 25, 2012 03:36
Show Gist options
  • Select an option

  • Save davidandrzej/2785612 to your computer and use it in GitHub Desktop.

Select an option

Save davidandrzej/2785612 to your computer and use it in GitHub Desktop.
Laziness, side-effects / mutability, and short-circuiting: a cautionary tale
scala> val mutant = collection.mutable.ListBuffer[Int]()
mutant: scala.collection.mutable.ListBuffer[Int] = ListBuffer()
scala> (0 until 4).view.map{idx => {
mutant.append(idx); idx > 0}}.exists(identity)
res3: Boolean = true
scala> mutant
res4: scala.collection.mutable.ListBuffer[Int] =
ListBuffer(0, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment