Hey! Say I have an arbitrary `List<Int>` whe...
# getting-started
g
Hey! Say I have an arbitrary
List<Int>
where every entry is a counter. What would be a Kotlin-esque way to map this into a
List<Int>
where at every index the entry is equal to the sum of counts until that index? For example,
[1, 3, 4, 2, 2]
becomes
[1, 4, 8, 10, 12]
due to the following summations:
[1, 1+3, 1+3+4, 1+3+4+2, 1+3+4+2+2]
c
A fold should do the trick, passing through the resulting list and the current accumulated value https://pl.kotl.in/wJudkD4RI
☝️ 1
g
Clever idea, thanks a lot!