In Scala, how do I fold a List and return the intermediate results?

前端 未结 8 972
失恋的感觉
失恋的感觉 2020-12-08 07:12

I\'ve got a List of days in the month:

val days = List(31, 28, 31, ...)

I need to return a List with the cumulative sum of days:

         


        
8条回答
  •  无人及你
    2020-12-08 07:45

    Fold into a list instead of an integer. Use pair (partial list with the accumulated values, accumulator with the last sum) as state in the fold.

提交回复
热议问题