filter, filterNot, and partition
Split and select elements using predicate-based functions.
Selection Operations
filter keeps elements matching a predicate. filterNot keeps those that do NOT match. partition splits the collection into two lists at once.
Basic filter
filter { ... } returns a new list containing only elements where the predicate is true.
fun main() {
val nums = listOf(1, 2, 3, 4, 5, 6)
val evens = nums.filter { it % 2 == 0 }
println(evens) // [2, 4, 6]
}