Change a list to map in Kotlin while customize this convert

Viewed 521
var listOfNums = listOf(1,9,8,25,5,44,7,95,9,10)
var mapOfNums = listOfNums.map { it to it+1 }.toMap()
println(mapOfNums)

result

{1=2, 9=10, 8=9, 25=26, 5=6, 44=45, 7=8, 95=96, 10=11}

while I need this result, it adds contents of next element to the current element while I need to map current element to next element

my goal result

{1=9, 8=25, 5=44, 7=59, 9=10}
3 Answers
Related