dimanche 15 mars 2020

Can I convert this if else statements into pattern matching without nested pattern matching in scala?

Say I have this conditions having all the values depending on each other -

val a = 9
val b = 89
val c = 0

val result =
  if (a == 0) 0
  else if (b == 4) 0
  else if (c < 90) 0
  else (a + b + c)

How to code this using pattern matching without nesting it or is it okay to code in this way. Is there some disadvantage of using if else condition in this situation instead of using pattern matching.

Aucun commentaire:

Enregistrer un commentaire