3 ms·
To me it seems really weird to have the function take a nullable string in the first place (and not obvious that null + 1 == 0), so the right solution is probab
by ptx 8y ago
To me it seems really weird to have the function take a nullable string in the first place (and not obvious that null + 1 == 0), so the right solution is probably to deal with the null values at some earlier stage – but in the interest of further bikeshedding of the implementation, a simple if-expression is pretty clean:
fun parseAndInc(number: String?) =
if (number != null) number.toInt() + 1 else 0
- V-2 8y agoOr fun parseAndInc(number: String?) = (number ?: "-1").toInt() + 1 ;)