Basically, any use case of foldl
where you also want the intermediate results.
If you want the sum of a list of numbers, you can write:
sum : List number -> number
sum = List.foldl (+) 0
Substituting scanl
gives you the cumulative sum, i.e. the list of intermediate sums:
cumulativeSum : List number -> List number
cumulativeSum =
scanl (+) 0
sum [1,2,3]
>> 6
cumulativeSum [1,2,3]
>> [0, 1, 3, 6]