Hey guys i am new to Kotlin and want to see what is the easiest way to increment value of a map by 1 on each iteration, here is my attempts
This is how my map looks like.
val countByStatus: MutableMap<ImportStatus, Int> = mutableMapOf()when (val count = csv.countByStatus[rowResult.status]) { null -> csv.countByStatus[rowResult.status] = 1 else -> csv.countByStatus[rowResult.status] = count + 1 }
or
csv.countByStatus.merge(rowResult.status, 1, Int::plus)
or
csv.countByStatus.merge(rowResult.status, 1, { a: Int?, b: Int? -> a!! + b!! })