How do you work with IList <> in F #?

I have a list of types IList<Effort>. The Force Model contains a float, called Amount. I would like to return the amount Amountfor the entire list in F #. How will this be achieved?

+3
source share
4 answers
efforts |> Seq.sumBy (fun e -> e.Amount)
+5
source

Simplified answers Seq.fold, pipelined Seq.foldand pipelined Seq.sumBy(I like the third option).

However, no one mentioned what the seq<'T>F # name is for IEnumerable<T>, so the module functions Seqwork on anyone IEnumerable, including ILists.

+5
source
Seq.fold (fun acc (effort: Effort) -> acc + effort.Amount) 0.0 efforts
+4

, , , . sepp2k , effort effort, ( effort.Amount, " ). :

efforts |> Seq.fold (fun acc effort -> acc + effort.Amount) 0.0  

effort, , efforts IList<Effort>. , , .

+3

Source: https://habr.com/ru/post/1739698/


All Articles