Last active
April 29, 2016 19:15
-
-
Save devth/10a2b47644015fe99b4b0cf529cf08ba to your computer and use it in GitHub Desktop.
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
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 | |
} |
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
(cost, method) match { | |
case (None, None) => None | |
case (c, m) => Some(List(c, m).flatten.mkString(" - ")) | |
} |
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
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