Created
March 27, 2014 00:37
-
-
Save mmynsted/9797243 to your computer and use it in GitHub Desktop.
The question was about creating an Option[String] from a Seq[String]
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 Main extends App { | |
def toOpt(s: Set[String]): Option[String] = s match { | |
case x if !x.isEmpty => Some(x.mkString(" ")) | |
case _ => None | |
} | |
val a: Set[String] = Set() | |
val b: Set[String] = Set("a", "b") | |
println(s"a = ${toOpt(a)}") | |
println(s"b = ${toOpt(b)}") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment