LeoColman
08/29/2021, 6:07 PMval myList = listOf("A", "AA", "B", "BB")
val aIndices = myList.mapIndexedNotNull { index, str -> if("A" in str) index else null } // 0 and 1
LeoColman
08/29/2021, 6:07 PMLeoColman
08/29/2021, 6:07 PMLeoColman
08/29/2021, 6:08 PMa.filter { predicate }.indices
, but in a way that would work instead of losing the indicesYoussef Shoaib [MOD]
08/29/2021, 6:43 PMmyList.withIndex().filter { "A" in it.value }.map(IndexedValue<*>::index)
Youssef Shoaib [MOD]
08/29/2021, 6:44 PMmyList.mapIndexedNotNull { index, str -> index.takeIf { "A" in str } }
LeoColman
08/29/2021, 8:30 PMLeoColman
08/29/2021, 8:30 PMtakeIf
was a nice catch, I forgot about it!