List.sumBy<'T,^U> Function (F#)
Returns the sum of the results generated by applying the function to each element of the list.
Namespace/Module Path: Microsoft.FSharp.Collections.List
Assembly: FSharp.Core (in FSharp.Core.dll)
// Signature: List.sumBy : ('T -> ^U) -> 'T list -> ^U (requires ^U with static member (+) and ^U with static member Zero) // Usage: List.sumBy projection list
// Compute the sum of the first 10 integers by using List.sum. let sum1 = List.sum [1 .. 10] // Compute the sum of the squares of the elements of a list by using List.sumBy. let sum2 = List.sumBy (fun elem -> elem*elem) [1 .. 10] // Compute the average of the elements of a list by using List.average. let avg1 = List.average [0.0; 1.0; 1.0; 2.0] printfn "%f" avg1