Suppose you have a value val list: List[Date]
. You would like to know if any one of the dates in this list occur after some startDate
. You could do this
list.fold(false)((a, b) => startDate.compareTo(b) < 0 || a)
which would return true
if any date occurred on or after startDate
thus achieving our objective.
However, since this is an OR statement being used, if even only one date satisfies the condition startDate.compareTo(b) < 0
, then the whole fold operation will return true
. Does Scala have a way of terminating execution of the fold and just returning the true
when it hits it?