mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
add CCArray.rev
This commit is contained in:
parent
f0381ae0d9
commit
a99720945b
2 changed files with 19 additions and 0 deletions
|
|
@ -350,6 +350,21 @@ let reverse_in_place a =
|
||||||
a = [| 6;5;4;3;2;1 |]
|
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 =
|
let find f a =
|
||||||
_find (fun _ -> f ) a 0 (Array.length a)
|
_find (fun _ -> f ) a 0 (Array.length a)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -143,6 +143,10 @@ include S with type 'a t := 'a t
|
||||||
|
|
||||||
val map : ('a -> 'b) -> 'a t -> 'b 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
|
val filter : ('a -> bool) -> 'a t -> 'a t
|
||||||
(** Filter elements out of the array. Only the elements satisfying
|
(** Filter elements out of the array. Only the elements satisfying
|
||||||
the given predicate will be kept. *)
|
the given predicate will be kept. *)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue