32 lines
565 B
Plaintext
32 lines
565 B
Plaintext
If the same logic is needed for both instances, then:
|
|
|
|
* in an `if` structure they should be combined
|
|
|
|
[source,scala,diff-id=1,diff-type=compliant]
|
|
----
|
|
if ((a >= 0 && a < 10) || (a >= 20 && a < 50)) {
|
|
doFirstThing
|
|
doTheThing
|
|
}
|
|
else if (a >= 10 && a < 20) {
|
|
doTheOtherThing
|
|
}
|
|
else {
|
|
doTheRest
|
|
}
|
|
----
|
|
|
|
* for a `match`, the values should be put in the `case` expression list.
|
|
|
|
[source,scala,diff-id=2,diff-type=compliant]
|
|
----
|
|
value match {
|
|
case 1 | 3 =>
|
|
doFirstThing
|
|
doSomething
|
|
case 2 =>
|
|
doSomethingDifferent
|
|
case _ =>
|
|
doTheRest
|
|
}
|
|
---- |