3 ms·
To reiterate OP's point about scala, in my idiomatic scala, I'd use a 3rd technique: def ABSOrSeven(maybeNumber: Option[Int]): Int = maybeNumber match {
by norir 3y ago
To reiterate OP's point about scala, in my idiomatic scala, I'd use a 3rd technique:
def ABSOrSeven(maybeNumber: Option[Int]): Int = maybeNumber match {
case Some(int) => Math.abs(int)
case None => 7
}
Somewhat more verbose but I think is the most clear and should have fewer function calls than the getOrElse version and has no unsafe operations like the (safely guarded) `maybeNumber.get` call.
The point though is that the author is correct that scala provides too many ways of doing the same thing such that disagreement is inevitable.
- TulliusCicero 3y agoThat's nice. The 3.1 version they used felt hard to immediately understand to me, a little too abstract.