Permalink
Browse files

added sum and fsum to array module for symmetry with List module.

  • Loading branch information...
1 parent 29f2ccb commit db360682aec7ea604f8c06461aee02029c4609e1 @rgrinberg committed Dec 31, 2012
Showing with 17 additions and 0 deletions.
  1. +11 −0 src/batArray.ml
  2. +6 −0 src/batArray.mli
View
@@ -542,6 +542,17 @@ let max a = reduce Pervasives.max a
max [|2;3;1|] = 3
*)
+let sum = reduce (+)
+let fsum = reduce (+.)
+
+(*$T sum
+ sum [|1;2;3|] = 6
+ sum [|0|] = 0
+*) (*$T fsum
+ fsum [|1.0;2.0;3.0|] = 6.0
+ fsum [|0.0|] = 0.0
+*)
+
(* meant for tests, don't care about side effects being repeated
or not failing early *)
let is_sorted_by f xs =
View
@@ -168,6 +168,12 @@ val min : 'a array -> 'a
@raise Invalid_argument on empty input *)
+val sum : int array -> int
+(** [sum l] returns the sum of the integers of [l] *)
+
+val fsum : float array -> float
+(** [fsum l] returns the sum of the floats of [l] *)
+
val left : 'a array -> int -> 'a array
(**[left r len] returns the array containing the [len] first
characters of [r]. If [r] contains less than [len] characters, it

0 comments on commit db36068

Please sign in to comment.