Created
June 18, 2015 07:43
-
-
Save ugdark/d468200470279dd49ba0 to your computer and use it in GitHub Desktop.
Some("")をNoneに変換したいがもっと綺麗にかけないのかなっと。
This file contains 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
object OptionSample extends App { | |
def stringEmptyToNone(code: Option[String]): Option[String] = { | |
code match { | |
case Some(s: String) => { | |
s.nonEmpty match { | |
case true => Some(s) | |
case _ => None | |
} | |
} | |
case _ => None | |
} | |
} | |
val v: Option[String] = Some("") | |
println(v.isEmpty) | |
println(stringEmptyToNone(v).isEmpty) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
.filter(_.nonEmpty)
でいけるっと