A question in essence similar to subtle differences between val and def. I wonder what's the semantic difference between having a member singleton object:
class Text {
...
object Whitespace { def unapply(s :String) =
if (s.forall(_.isWhitespace)) Some(s) else None
}
}
and
class Text {
...
val Whitespace = new { def unapply(s :String) =
if (s.forall(_.isWhitespace)) Some(s) else None
}
}
I know how both translate to bytecode, but what can I do with one in the code that I can't with the other?