I have a simple problem and as I'm an F# newbie I can't seem to figure out how to do this. I have a list of tuples:

let l = [ (a, 2); (b, 3); (c, 2); (d, 6) ]


that I want to transform into this:

let r = [ (a, 2); (b, 5); (c, 7); (d, 13) ]


This simply adds the values of the second element in each tuple: 2 + 3 + 2 + 6. The objects a, b, c and d are complex objects that I simply want to keep.

I thought I should use List.scan for this. It takes a list, threads an accumulator through the computation and returns a list:

let r = l |&gt; List.scan (fun (_, s) (o, i) -&gt; (o, s + i)) (??, 0) |&gt; List.tail


But I don't know what to fill in for the question marks. I'm not interested in the initial state except for the 0. And I don't want to specify some 'empty' instance of the first tuple element.

Or is there a simpler way of doing this?


Question: Get list of all files by mask in terminal
Answer: You can use -o for "or":

find . -path '*/trunk/src/*.h' -o -path '*/trunk/src/*.cpp'


which is the same as

find . -path '*/trunk/src/*' \( -name '*.h' -o -name '*.cpp' \)


If you want to run grep on these files:

find . \( -path '*/trunk/src/*.h' -o -path '*/trunk/src/*.cpp' \) -exec grep PATTERN {} +


or

find . -path '*/trunk/src/*' \( -name '*.h' -o -name '*.cpp' \) -exec grep PATTERN {} +