diff --git a/src/core/CCArray.ml b/src/core/CCArray.ml index 2c338642..9ac0d744 100644 --- a/src/core/CCArray.ml +++ b/src/core/CCArray.ml @@ -44,6 +44,7 @@ let get_safe a i = None let map_inplace f a = Array.iteri (fun i e -> Array.unsafe_set a i (f e)) a +let mapi_inplace f a = Array.iteri (fun i e -> Array.unsafe_set a i (f i e)) a let fold = Array.fold_left let foldi f acc a = diff --git a/src/core/CCArray.mli b/src/core/CCArray.mli index de08d819..a3258097 100644 --- a/src/core/CCArray.mli +++ b/src/core/CCArray.mli @@ -64,6 +64,10 @@ val map_inplace : ('a -> 'a) -> 'a t -> unit (** [map_inplace f a] replace all elements of [a] by its image by [f]. @since 3.8 *) +val mapi_inplace : (int -> 'a -> 'a) -> 'a t -> unit +(** [mapi_inplace f a] replace all elements of [a] by its image by [f]. + @since NEXT_RELEASE *) + val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a (** [fold f init a] computes [f (… (f (f init a.(0)) a.(1)) …) a.(n-1)], where [n] is the length of the array [a]. diff --git a/src/core/CCArrayLabels.mli b/src/core/CCArrayLabels.mli index e9b2c649..2cddc210 100644 --- a/src/core/CCArrayLabels.mli +++ b/src/core/CCArrayLabels.mli @@ -62,6 +62,10 @@ val map_inplace : f:('a -> 'a) -> 'a t -> unit (** [map_inplace ~f a] replace all elements of [a] by its image by [f]. @since 3.8 *) +val mapi_inplace : f:(int -> 'a -> 'a) -> 'a t -> unit +(** [mapi_inplace ~f a] replace all elements of [a] by its image by [f]. + @since NEXT_RELEASE *) + val fold : f:('a -> 'b -> 'a) -> init:'a -> 'b t -> 'a (** [fold ~f ~init a] computes [f (… (f (f init a.(0)) a.(1)) …) a.(n-1)], where [n] is the length of the array [a].