Skip to content

Instantly share code, notes, and snippets.

@ugdark
Created June 18, 2015 07:43
Show Gist options
  • Save ugdark/d468200470279dd49ba0 to your computer and use it in GitHub Desktop.
Save ugdark/d468200470279dd49ba0 to your computer and use it in GitHub Desktop.
Some("")をNoneに変換したいがもっと綺麗にかけないのかなっと。
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)
}
@ugdark
Copy link
Author

ugdark commented Jun 18, 2015

.filter(_.nonEmpty)
でいけるっと

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