I hoped that there might be something in the standard lib. Anyway, I like your implementation!
A slightly more concise variant of your indexMap
function:
fun <T> Iterable<T>.indexMap(): Map<T, Int> =
this.mapIndexed { i, v -> Pair(v, i) }.toMap()
However, your version might be a bit more efficient, since no intermediate list as a result of mapIndexed
is needed.