Skip to content

Commit 5227fb9

Browse files
committed
feat(CCArray): add mapi_inplace
1 parent e0a8285 commit 5227fb9

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

src/core/CCArray.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ let get_safe a i =
4444
None
4545

4646
let map_inplace f a = Array.iteri (fun i e -> Array.unsafe_set a i (f e)) a
47+
let mapi_inplace f a = Array.iteri (fun i e -> Array.unsafe_set a i (f i e)) a
4748
let fold = Array.fold_left
4849

4950
let foldi f acc a =

src/core/CCArray.mli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ val map_inplace : ('a -> 'a) -> 'a t -> unit
6464
(** [map_inplace f a] replace all elements of [a] by its image by [f].
6565
@since 3.8 *)
6666

67+
val mapi_inplace : (int -> 'a -> 'a) -> 'a t -> unit
68+
(** [mapi_inplace f a] replace all elements of [a] by its image by [f].
69+
@since NEXT_RELEASE *)
70+
6771
val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
6872
(** [fold f init a] computes [f (… (f (f init a.(0)) a.(1)) …) a.(n-1)],
6973
where [n] is the length of the array [a].

src/core/CCArrayLabels.mli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ val map_inplace : f:('a -> 'a) -> 'a t -> unit
6262
(** [map_inplace ~f a] replace all elements of [a] by its image by [f].
6363
@since 3.8 *)
6464

65+
val mapi_inplace : f:(int -> 'a -> 'a) -> 'a t -> unit
66+
(** [mapi_inplace ~f a] replace all elements of [a] by its image by [f].
67+
@since NEXT_RELEASE *)
68+
6569
val fold : f:('a -> 'b -> 'a) -> init:'a -> 'b t -> 'a
6670
(** [fold ~f ~init a] computes [f (… (f (f init a.(0)) a.(1)) …) a.(n-1)],
6771
where [n] is the length of the array [a].

0 commit comments

Comments
 (0)