📜  kotlin 按谓词拆分列表 - Kotlin 代码示例

📅  最后修改于: 2022-03-11 14:53:31.980000             🧑  作者: Mango

代码示例1
fun main() {
    val asha = Student(101, "Asha", "IT")
    val john = Student(102, "John", "Mechanic")
    val afra = Student(103, "Afra", "Bio")
    val kyle = Student(104, "Kyle", "IT")
    val studentList = listOf(asha, john, afra, kyle)
    val (itDept, others) = studentList.partition {
        student -> student.dept.equals("IT")
    }
    println(itDept)
    println(others) 
}
data class Student(val id: Long, val name: String, val dept: String)