Kotlin’s coerceIn throws « Cannot coerce value to an empty range » instead of clamping
coerceIn(0, n – 1) is not a safe clamp: when n == 0 the range is empty and Kotlin throws IllegalArgumentException. Floor the upper bound or guard n == 0.
coerceIn(0, n – 1) is not a safe clamp: when n == 0 the range is empty and Kotlin throws IllegalArgumentException. Floor the upper bound or guard n == 0.