Quantcast
Channel: Increment value by 1 on each iteration in map - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Increment value by 1 on each iteration in map

$
0
0

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!! })

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images