summaryrefslogtreecommitdiff
path: root/stdlib/array.ml
diff options
context:
space:
mode:
authorBernhard Schommer <bernhardschommer@gmail.com>2015-11-30 00:53:19 +0100
committerBernhard Schommer <bernhardschommer@gmail.com>2015-12-04 00:41:29 +0100
commitd3aa77961c8759b8ea02a67a2ca8f732e8f825e2 (patch)
tree3bf476c7e4cd4c12f14cd2e360d82a549e7662ca /stdlib/array.ml
parente8625747fa4d96b0e42bc5568e4efb3b288ec320 (diff)
downloadocaml-d3aa77961c8759b8ea02a67a2ca8f732e8f825e2.tar.gz
Add exist and for_all to array.
Implemented an exist and a for_all function for arrays with the same interfaces as the ones for lists.
Diffstat (limited to 'stdlib/array.ml')
-rw-r--r--stdlib/array.ml14
1 files changed, 14 insertions, 0 deletions
diff --git a/stdlib/array.ml b/stdlib/array.ml
index 3662b9f1da..77a458ff54 100644
--- a/stdlib/array.ml
+++ b/stdlib/array.ml
@@ -134,6 +134,20 @@ let fold_right f a x =
done;
!r
+let exists p a =
+ let f = ref false in
+ for i = 0 to length a - 1 do
+ f := !f || p (unsafe_get a i)
+ done;
+ !f
+
+let for_all p a =
+ let f = ref true in
+ for i = 0 to length a - 1 do
+ f := !f && p (unsafe_get a i)
+ done;
+ !f
+
exception Bottom of int;;
let sort cmp a =
let maxson l i =