mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
feat(CCArray): add mapi_inplace
This commit is contained in:
parent
e0a8285e17
commit
5227fb975c
3 changed files with 9 additions and 0 deletions
|
|
@ -44,6 +44,7 @@ let get_safe a i =
|
||||||
None
|
None
|
||||||
|
|
||||||
let map_inplace f a = Array.iteri (fun i e -> Array.unsafe_set a i (f e)) a
|
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 fold = Array.fold_left
|
||||||
|
|
||||||
let foldi f acc a =
|
let foldi f acc a =
|
||||||
|
|
|
||||||
|
|
@ -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].
|
(** [map_inplace f a] replace all elements of [a] by its image by [f].
|
||||||
@since 3.8 *)
|
@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
|
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)],
|
(** [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].
|
where [n] is the length of the array [a].
|
||||||
|
|
|
||||||
|
|
@ -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].
|
(** [map_inplace ~f a] replace all elements of [a] by its image by [f].
|
||||||
@since 3.8 *)
|
@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
|
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)],
|
(** [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].
|
where [n] is the length of the array [a].
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue