How to simplify when expression in kotlin
I’d like to simplify this expression, especially "isDigit" and "isLetter" case. How to do it? smoothInput.forEach { char -> when { char.isValidOperator() -> { output.push(char) } char.isDigit() -> { if (output.isNotEmpty() && output.last()!!.isNumeric()) output.addToLast(char) else output.push(char) } char.isLetter() -> { if (output.isNotEmpty() && output.last()!!.isValidVariableName()) output.addToLast(char) else output.push(char) } else -> { throw InvalidIdentifierException() } }… Read More How to simplify when expression in kotlin