avatar

Andres Jaimes

Check multiple option values in Scala

By Andres Jaimes

- 1 minutes read - 49 words

Two main approaches for doing this, the second one being for me the most appropriate.

Check values using regular if conditions:

if (opt1.isDefined && opt2.isDefined && opt3.isDefined) // do something

Check values using match:

(opt1, opt2, opt3) match {
  case(Some(val1), Some(val2), Some(val3)) => ???
  case _ => ???
}