Consider the following list of Boolean values in Scala
List(true, false, false, true)
How would you using either foldRight or foldLeft emulate
Instead of using foldLeft/Right, you can also use forall(identity) for the logical AND, or exists(identity) for the logical OR.
foldLeft/Right
forall(identity)
exists(identity)
edit: The benefit of these functions is the early exit. If forall hits a false or exists a true, they will immediately return.
forall
false
exists
true