Hi,
This is something that has puzzled me for some time, but I never thought about asking to a broader audience.
The forall
method returns true if the collection or Option is empty. How does it even make any sense?
For example, we take an empty Option, all predicates making assertions about its content should return false. The same is valid for Scala collections.
@ val optEmpty: Option[String] = None
optEmpty: Option[String] = None
@ optEmpty.forall(_.startsWith("a"))
res6: Boolean = true
@ optEmpty.forall(_.startsWith("b"))
res6: Boolean = true
IMO, if something is empty and I want to make an assertion about its content than the predicate must always return false.
There is an open PR for play-json
(see comment) that introduces forall
on JsResult
and it’s following the same logic. Fair enough, it’s good to keep consistency in the ecosystem. However, I was just wondering what is the rationale behind this choice.