If it is not important that the items are removed ...
# announcements
j
If it is not important that the items are removed before the notification, then you can use this. Unfortunately, there is no
onEachIndexed
, so it is verbose and slow:
Copy code
val data = listOf("foo", null, "bar", null, "baz")
    val dataWithoutNulls = data
    	.withIndex()
    	.onEach { indexedItem -> if (indexedItem.value == null) { println("Notify ${indexedItem.index}") } }
    	.map { indexedItem -> indexedItem.value }
    	.filterNotNull()
    println(dataWithoutNulls)