diff --git a/src/core/CCArray.ml b/src/core/CCArray.ml index a7230a77..7c38eb45 100644 --- a/src/core/CCArray.ml +++ b/src/core/CCArray.ml @@ -350,6 +350,21 @@ let reverse_in_place a = a = [| 6;5;4;3;2;1 |] *) +let rev a = + let b = Array.copy a in + reverse_in_place b; + b + +(*$Q + Q.(array small_int) (fun a -> rev (rev a) = a) +*) + +(*$T + rev [| 1; 2; 3 |] = [| 3; 2; 1 |] + rev [| 1; 2; |] = [| 2; 1 |] + rev [| |] = [| |] + *) + let find f a = _find (fun _ -> f ) a 0 (Array.length a) diff --git a/src/core/CCArray.mli b/src/core/CCArray.mli index eb6b9d29..fd7eb5bb 100644 --- a/src/core/CCArray.mli +++ b/src/core/CCArray.mli @@ -143,6 +143,10 @@ include S with type 'a t := 'a t val map : ('a -> 'b) -> 'a t -> 'b t +val rev : 'a t -> 'a t +(** Copy + reverse in place + @since NEXT_RELEASE *) + val filter : ('a -> bool) -> 'a t -> 'a t (** Filter elements out of the array. Only the elements satisfying the given predicate will be kept. *)