My colleague and I had a bug that was due to our assumption that an empty stream calling allMatch()
would return false
.
if (myItems.allMatch(i -> i.isValid()) {
//do something
}
Of course, it is kind of our fault for assuming and not reading documentation. But what I don't understand is why the default allMatch()
behavior for an empty stream returns true
. What was the reasoning for this? Like the anyMatch()
(which contrarily returns false), this operation is used in an imperative way that departs the monad and probably used in an if
statement. Considering those facts, is there any reason why having allMatch()
default to true
on an empty stream be desirable for majority of uses?
allMatch
returns true then so shouldanyMatch
. Additionally, for the empty case,allMatch(...) == noneMatch(...)
which is also weird. – Vulgariani -> i.isValid()
, you can writeFoo::isValid
(whereFoo
is whatever class you're streaming, of course) – Noetic