Skip to content

Instantly share code, notes, and snippets.

@mmynsted
Created March 27, 2014 00:37
Show Gist options
  • Save mmynsted/9797243 to your computer and use it in GitHub Desktop.
Save mmynsted/9797243 to your computer and use it in GitHub Desktop.
The question was about creating an Option[String] from a Seq[String]
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