I recently had the need to implement Luhn's Algorithm in a Java/Kotlin application. I needed a function that would add the check digit to the string of a number like a credit card or IMEI. It could be easily modified to check if the last digit is valid.At first, I had a code of around 20 lines in Java, but by using every Kotlin quirk I could think of, I managed to do it in one line. fun String.addLastImeiDigit(): String = $this${10 - this.withIndex().map { if (it.index.and(1) == 0) it.value.toInt() - 48 else (2 * (it.value.toInt() - 48)).run { (this % 10) + (this / 10) } }.sum() % 10}Here it is in a more understandable fashionfun String.addLastImeiDigit(): String {    return $this${10 - this.withIndex().map {        if (it.index.and(1) == 0) /* if even */            it.value.toInt() - 48 /* ascii to Int */        else            (2 * (it.value.toInt() - 48)).run {                (this % 10) + (this / 10) /* sum both digits */            }    }.sum() % 10}}I understand that obfuscating code like this in a shared code environment would be very bad, but still I think it's great that we can get to do this and that Kotlin avoids so much boilerplate. What do you think about using one-line functions like this one?
Credit card / IMEI check digit in Kotlin
algorithm;lambda;extension methods;checksum;kotlin