Created
September 30, 2013 13:17
-
-
Save gbougeard/6763689 to your computer and use it in GitHub Desktop.
noneIfEmpty
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def noneIfEmpty(str:Option[String]) = { | |
| str match { | |
| case Some(s) => s match { | |
| case s.trim.isEmpty => None | |
| case s => s | |
| } | |
| case None => None | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
def noneIfEmpty(strOpt:Option[String]) = strOpt.filterNot(isEmptyString)
isEmptyString is left as an exercice.. :)