Skip to content

Instantly share code, notes, and snippets.

@devth
Last active April 29, 2016 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devth/10a2b47644015fe99b4b0cf529cf08ba to your computer and use it in GitHub Desktop.
Save devth/10a2b47644015fe99b4b0cf529cf08ba to your computer and use it in GitHub Desktop.
val cost: Option[String] = Some("123")
val method: Option[String] = None
(cost, method) match {
case (Some(c), Some(m)) => Some(s"$c $m")
case (Some(c), None) => Some(s"$c")
case (None, Some(m)) => Some(s"$m")
case _ => None
}
(cost, method) match {
case (None, None) => None
case (c, m) => Some(List(c, m).flatten.mkString(" - "))
}
List(cost, method).flatten.mkString(" ").some.filter(_.nonEmpty)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment