diff options
| author | Bernhard Schommer <bernhardschommer@gmail.com> | 2015-11-30 00:53:19 +0100 |
|---|---|---|
| committer | Bernhard Schommer <bernhardschommer@gmail.com> | 2015-12-04 00:41:29 +0100 |
| commit | d3aa77961c8759b8ea02a67a2ca8f732e8f825e2 (patch) | |
| tree | 3bf476c7e4cd4c12f14cd2e360d82a549e7662ca /stdlib/array.ml | |
| parent | e8625747fa4d96b0e42bc5568e4efb3b288ec320 (diff) | |
| download | ocaml-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.ml | 14 |
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 = |
