kotlin split list by predicate

fun <T> List<T>.splitByPredicate(predicate: (T) -> Boolean): Pair<List<T>, List<T>> {
    val firstList = mutableListOf<T>()
    val secondList = mutableListOf<T>()

    for (element in this) {
        if (predicate(element)) {
            firstList.add(element)
        } else {
            secondList.add(element)
        }
    }

    return Pair(firstList, secondList)
}

fun main() {
    val originalList = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9)
    val (evenNumbers, oddNumbers) = originalList.splitByPredicate { it % 2 == 0 }

    println("Even numbers: $evenNumbers")
    println("Odd numbers: $oddNumbers")
}