I wonder if there is some function in the F# libraries similar to this one?
let map_acc (f:int->int) (list:int list) =
let rec map_acc' f acc = function
| [] -> []
| h::t -> (f (h+acc))::(map_acc' f (h+acc) t)
map_acc' f 0 list
Usage:
let xxx = map_acc id [1..10]
val xxx : int list = [1; 3; 6; 10; 15; 21; 28; 36; 45; 55]
Its purpose is quite similar to map‘s but it passes the current state (in the given case, an accumulator) to each element of the list.
Yes, List.scan is the missing key you seek: