Skip to content

Commit

Permalink
Merge pull request #159 from orbifx/master
Browse files Browse the repository at this point in the history
Add `CCImmutArray.sub`, which creates a copy
  • Loading branch information
c-cube committed Nov 20, 2017
2 parents 3b50617 + a28dd39 commit 170d766
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/data/CCImmutArray.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ let set a n x =
a'.(n) <- x;
a'

let sub = Array.sub (* Would this not be better implemented with CCArray_slice *)

let map = Array.map

let mapi = Array.mapi
Expand Down
9 changes: 9 additions & 0 deletions src/data/CCImmutArray.mli
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ val get : 'a t -> int -> 'a
val set : 'a t -> int -> 'a -> 'a t
(** Copy the array and modify its copy *)

val sub : 'a t -> int -> int -> 'a t
(** [sub a start len] returns a fresh array of length len, containing the elements
from [start] to pstart + len - 1] of array a.
Raises [Invalid_argument "Array.sub"] if [start] and [len] do not designate a
valid subarray of a; that is, if start < 0, or len < 0, or start + len > Array.length a.
@since NEXT_RELEASE *)

val map : ('a -> 'b) -> 'a t -> 'b t

val mapi : (int -> 'a -> 'b) -> 'a t -> 'b t
Expand Down

0 comments on commit 170d766

Please sign in to comment.