I have ran into this need several times and have not found a good, concise way to do it and want to know am I just missing it or is this something that is missing from the standard library.
The issue is with the need to do a map type operation where the thing you are mapping to is dependent on doing some type of accumulation operation on the values up to that point. There is map which lets you transform, but all you get is the single value to do the transformation on. There are fold and reduce that let you do accumulation operations, but only give you the single final result.
So for example lets say I have
val x = arrayOf(1, 2, 3, 4, 5, 6)
and what I want to is apply some operation(s) on x to arrive at a transformed version where the values are replaced by the values so far. The result would be an equivalent to:
val result = arrayOf(1, 3, 6, 10, 15, 21)
The only somewhat functional way I can see to do it is use a fold where the accumulator type is a pair that has the accumulation value and a collection that you add to.
In my actual case I have a collection of collections and basically want to create pairs made up of the sum of item counts so far to the collection, which will be an index for viewing them as one big collection.
Is there a good way to do something like this or is this something missing in the library?