mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 11:45:31 -05:00
feat(ccarray): add CCArray.map_inplace
This commit is contained in:
parent
e59cc68c24
commit
8a71b1dcaa
3 changed files with 21 additions and 5 deletions
|
|
@ -52,6 +52,16 @@ let get_safe a i =
|
|||
None (get_safe [|1;2;3|] ~-42)
|
||||
*)
|
||||
|
||||
let map_inplace f a =
|
||||
Array.iteri (fun i e -> Array.unsafe_set a i (f e)) a
|
||||
|
||||
(*$Q
|
||||
Q.(array int) (fun a -> \
|
||||
let b = map ((+) 1) a in \
|
||||
map_inplace ((+) 1) a; \
|
||||
b = a)
|
||||
*)
|
||||
|
||||
let fold = Array.fold_left
|
||||
|
||||
let foldi f acc a =
|
||||
|
|
|
|||
|
|
@ -58,6 +58,9 @@ val get_safe : 'a t -> int -> 'a option
|
|||
(** [get_safe a i] returns [Some a.(i)] if [i] is a valid index.
|
||||
@since 0.18 *)
|
||||
|
||||
val map_inplace : ('a -> 'a) -> 'a t -> unit
|
||||
(** [map_inplace f a] replace all elements of [a] by its image by [f]. *)
|
||||
|
||||
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].
|
||||
|
|
|
|||
|
|
@ -32,17 +32,17 @@ type 'a t = 'a array
|
|||
[@@@else_]
|
||||
|
||||
include module type of ArrayLabels
|
||||
(** {{: http://caml.inria.fr/pub/docs/manual-ocaml/libref/ArrayLabels.html} Documentation for the standard ArrayLabels module}*)
|
||||
|
||||
module Floatarray = CCArray.Floatarray
|
||||
type 'a t = 'a array
|
||||
(** @inline
|
||||
{{: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Array.html} Documentation for the standard Array module}*)
|
||||
|
||||
module Floatarray = CCArray.Floatarray
|
||||
|
||||
type 'a t = 'a array
|
||||
|
||||
[@@@endif]
|
||||
|
||||
val empty : 'a t
|
||||
(** [empty] is the empty array, physically equal to [||]. *)
|
||||
(** [empty] is the empty array, physically equal to [[||]]. *)
|
||||
|
||||
val equal : 'a equal -> 'a t equal
|
||||
(** [equal eq a1 a2] is [true] if the lengths of [a1] and [a2] are the same
|
||||
|
|
@ -59,6 +59,9 @@ val get_safe : 'a t -> int -> 'a option
|
|||
(** [get_safe a i] returns [Some a.(i)] if [i] is a valid index.
|
||||
@since 0.18 *)
|
||||
|
||||
val map_inplace : f:('a -> 'a) -> 'a t -> unit
|
||||
(** [map_inplace ~f a] replace all elements of [a] by its image by [f]. *)
|
||||
|
||||
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].
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue