I want to filter out empty strings to put them into an Option. So I quickly built this now:
def StrictOption(s: String) = s match { case s if s != null && s.trim.length() > 0 => Some(s) case _ => None }
Question: is this maybe already somewhere in the standard library?
I don't think there's one single method in the standard library to do this, but you can do this much more tersely than your implementation.
Option(s).filter(_.trim.nonEmpty)
1.4m articles
1.4m replys
5 comments
56.9k users