Credit card / IMEI check digit in Kotlin
I personally like one-line functions as long as they are short but I also prefer breaking things out into smaller functions and/or objects to improve readability, reuse, etc. e.g.:

fun String.plusLuhnCheckDigit() = this + luhnCheckDigit(this)
fun luhnCheckDigit(digits: CharSequence): Char {
    return digits.sumByIndexed { index, digit -&gt;
        when {
            index.isEven -&gt; digit.asInt()
            else -&gt; sumDigits(2 * digit.asInt())
        }
    }.let { sum -&gt; 10 - sum % 10 }.asChar()
}


With the following also defined:

Strings.kt

inline fun CharSequence.sumByIndexed(selector: (Int, Char) -&gt; Int): Int {
    return foldIndexed(0) { index, sum, element -&gt; sum + selector(index, element) }
}


Numbers.kt

val Int.isEven: Boolean
    get() = and(1) == 0


NumericalChars.kt

fun Char.asInt() = toInt() - 48
fun Int.asChar() = toChar() + 48


IntMath.kt

val Int.magnitude: Int
    get() = if (this &lt; 0) -this else this

fun sumDigits(n: Int): Int = if (n.magnitude &lt; 10) n else n % 10 + sumDigits(n / 10)