Skip to content

Instantly share code, notes, and snippets.

@xnull
Created September 23, 2016 15:20
Show Gist options
  • Save xnull/4f5a86cff3027dff498cea72b6f6cd5d to your computer and use it in GitHub Desktop.
Save xnull/4f5a86cff3027dff498cea72b6f6cd5d to your computer and use it in GitHub Desktop.
object Main extends App {
val a: Option[Int] = Some(1)
val b: Option[Int] = None
val c: Option[Int] = Some(2)
(a, b, c) match {
case (Some(x), None, Some(z)) =>
println("1")
case (Some(x), Some(y), None) =>
println("2")
}
val multi: (Option[Int], Option[Int], Option[Int]) = (a, b, c)
val multiList: List[Option[Int]] = a :: b :: c :: Nil
multiList match {
case l if l.forall(_.nonEmpty) =>
println("wowowo")
case Some(x) :: Some(z) :: Some(y) :: Nil =>
println(s"a: $x, c: $y")
case Nil =>
println("Oh no, everything is wrong")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment