Skip to content

Commit

Permalink
add docs for resizearray
Browse files Browse the repository at this point in the history
  • Loading branch information
DoganCK committed Nov 6, 2023
1 parent 8eae9a9 commit 19358ac
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/FSharpAux.Core/ResizeArray.fs
Original file line number Diff line number Diff line change
Expand Up @@ -402,23 +402,34 @@ module ResizeArray =
accv <- currv
accv

/// <summary>Sums all the values in the <paramref name="array"/>.</summary>
/// <param name="array">The input ResizeArray.</param>
/// <returns>The resulting sum.</returns>
let inline sum (array: ResizeArray< ^T>) =
checkNonNull "array" array
let mutable acc = LanguagePrimitives.GenericZero< ^T>
for i = 0 to array.Count - 1 do
acc <- Checked.(+) acc array.[i]
acc

/// <summary>Returns the sum of the results generated by applying the function (<paramref name="projection"/>) to each element of the <paramref name="array"/>.</summary>
/// <param name="projection">The function to transform the ResizeArray elements into the type to be summed.</param>
/// <param name="array">The input ResizeArray.</param>
/// <returns>The resulting sum.</returns>
let inline sumBy ([<InlineIfLambda>] projection: 'T -> ^R) (array: ResizeArray<'T>) =
checkNonNull "array" array
let mutable acc = LanguagePrimitives.GenericZero< ^R>
for i = 0 to array.Count - 1 do
acc <- Checked.(+) acc (projection array.[i])
acc

let countIf (projection: 'T -> bool) (arr: ResizeArray<'T>): int =
/// <summary>Counts the number of elements in the <paramref name="array"/> satisfying the <paramref name="predicate"/>.</summary>
/// <param name="predicate">The function to transform the ResizeArray elements into the type to be summed.</param>
/// <param name="array">The input ResizeArray.</param>
/// <returns>Number of elements satisfying the <paramref name="predicate"/>.</returns>
let countIf (predicate: 'T -> bool) (arr: ResizeArray<'T>): int =
let mutable acc = 0
for i=0 to arr.Count - 1 do
if projection arr.[i] then
if predicate arr.[i] then
acc <- acc + 1
acc

0 comments on commit 19358ac

Please sign in to comment.