Skip to content

Commit

Permalink
added sum and fsum to array module for symmetry with List module.
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrinberg committed Dec 31, 2012
1 parent 29f2ccb commit db36068
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/batArray.ml
Expand Up @@ -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 =
Expand Down
6 changes: 6 additions & 0 deletions src/batArray.mli
Expand Up @@ -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
Expand Down

0 comments on commit db36068

Please sign in to comment.