Skip to content

Instantly share code, notes, and snippets.

@JoolsF
Last active July 23, 2016 13:58
Show Gist options
  • Save JoolsF/c9fcd5721de076426e7c1b14e72c9812 to your computer and use it in GitHub Desktop.
Save JoolsF/c9fcd5721de076426e7c1b14e72c9812 to your computer and use it in GitHub Desktop.
Testing boolean sequences with foldLeft
val truelist = List(true, true, true)
val falselist = List(false, false, false)
val trueFalseList = truelist ::: falselist
truelist.foldLeft(true){ (a,b) => a && b} //true
falselist.foldLeft(true){ (a,b) => a && b} //false
trueFalseList.foldLeft(true){ (a,b) => a && b} //false
//You could also write something like
truelist.forall(_== true) //true
//etc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment