Gunis
Tim Malseed
list.mapIndexedNotNull { index, item -> if (item == condition) { Pair(index, item) } else { null } }
Al Warren
val numbers = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9) val indices = numbers.indices .filter { numbers[it] % 2 == 0 } println(indices) println(numbers.slice(indices)) // output // [1, 3, 5, 7] // [2, 4, 6, 8]
A modern programming language that makes developers happier.