Last active
July 23, 2016 13:58
-
-
Save JoolsF/c9fcd5721de076426e7c1b14e72c9812 to your computer and use it in GitHub Desktop.
Testing boolean sequences with foldLeft
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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