<commit_before>object Luhn {
    fun isValid(numberCode: String): Boolean {
        val filteredCode = numberCode.filter { !it.isWhitespace() }
        if (filteredCode.length < 2) {
            return false
        }

        val numberSequence = filteredCode.reversedNumberSequence()
        if (numberSequence.containsInvalidCharacters()) {
            return false
        }

        return numberSequence
                .mapIndexed { index, digit -> doubleEverySecond(index + 1, digit) }
                .map { subtractWhenDoubleDigit(it) }
                .sum()
                .isDivisibleBy(10)
    }

    private fun String.reversedNumberSequence() =
            reversed().map { it.parseCharacter() }

    private fun List<Int>.containsInvalidCharacters() = any { it !in 0..9 }

    private fun doubleEverySecond(index: Int, digit: Int) =
            if (index.isDivisibleBy(2)) digit * 2 else digit

    private fun Int.isDivisibleBy(divisor: Int) = (this) % divisor == 0

    private fun subtractWhenDoubleDigit(it: Int) =
            if (it > 9) it - 9 else it

    private fun Char.parseCharacter() = toInt() - '0'.toInt()
}<commit_msg>some renaming<commit_after>object Luhn {
    fun isValid(numberCode: String): Boolean {
        val filteredCode = numberCode.filter { !it.isWhitespace() }
        if (filteredCode.length < 2) {
            return false
        }

        val numberSequence = filteredCode.reversedNumberSequence()
        if (numberSequence.containsInvalidCharacters()) {
            return false
        }

        return numberSequence
                .mapIndexed(this::doubleEverySecondOne)
                .map(this::toSingleDigit)
                .sum()
                .isDivisibleBy(10)
    }

    private fun String.reversedNumberSequence() =
            reversed().map { it.parseCharacter() }

    private fun List<Int>.containsInvalidCharacters() = any { it !in 0..9 }

    private fun doubleEverySecondOne(index: Int, digit: Int) =
            if ((index + 1).isDivisibleBy(2)) digit * 2 else digit

    private fun toSingleDigit(it: Int) = if (it > 9) it - 9 else it

    private fun Int.isDivisibleBy(divisor: Int) = (this) % divisor == 0

    private fun Char.parseCharacter() = toInt() - '0'.toInt()
}
{'fraction_non_alphanumeric': 0.10746003552397869, 'fraction_numerical': 0.010657193605683837, 'mean_word_length': 2.2510822510822512, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5268142', 'n_tokens_mistral': 673, 'n_tokens_neox': 621, 'n_words': 158}