Skip to content

Instantly share code, notes, and snippets.

@gbougeard
Created September 30, 2013 13:17
Show Gist options
  • Select an option

  • Save gbougeard/6763689 to your computer and use it in GitHub Desktop.

Select an option

Save gbougeard/6763689 to your computer and use it in GitHub Desktop.
noneIfEmpty
def noneIfEmpty(str:Option[String]) = {
str match {
case Some(s) => s match {
case s.trim.isEmpty => None
case s => s
}
case None => None
}
}
@sledorze

Copy link
Copy Markdown

def noneIfEmpty(strOpt:Option[String]) = strOpt.filterNot(isEmptyString)

isEmptyString is left as an exercice.. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment