Scala Optional doubt filter method
I was reading through the Scala docs, and looking through the Option
class I saw an implementation filter
that looks like this:
final def filter(p: A => Boolean): Option[A] =
if (isEmpty || p(this.get)) this else None
Why do we need to check if our instance is empty Option
? Wouldn't that lead to None
anyway?
+3
source to share