Check if a string is blank or doesn't exist in Scala

What you should do is check using exists. Like so:

myOption.exists(_.trim.nonEmpty)

which will return True if and only if the Option[String] is not None and not empty.


An approach based in pattern matching,

def isBlank( input : Option[String]) : Boolean = 
  input match {
    case None    => true
    case Some(s) => s.trim.isEmpty
  }

This should work as well since filter of an empty Option results in an empty Option

def isBlank( input : Option[String]) : Boolean =  
   input.filter(_.trim.length > 0).isEmpty