I've this following function, which maps ids to a list of Strings
private fun doIdMapping(resourcesList: List<String>): List<Pair<Int, String>> {
var id = 4
return resourcesList.map { resource ->
id++
id to resource
}
}
The id starts from 5 as you can see here. I can make this code look cleaner if id started from 0. Just like this
private fun doIdMapping(resourcesList: List<String>): List<Pair<Int, String> = resourcesList.mapIndexed { index, resource ->
index to resource
}
Is there some Kotlin function to achieve the first result without the use of var id. Maybe some function whose index starts at 5?