I don't understand when forAll deals with None values.
def areTheyEqual(x: Option[String], y: String) = {
if (x.forall(_ == y)) {
true
} else {
false
}
}
When I call the function:
areTheyEqual(None, "hello") this returns true, when I expect this to be false since they are not equal. Please help. Why is it like this?
Edit:
To solve this, I changed the if statement to:
if (x.nonEmpty && x.forall(_ == y))
But I still want to know why it returned true without the x.nonEmpty condition.