File tree 5 files changed +157
-78
lines changed
5 files changed +157
-78
lines changed Original file line number Diff line number Diff line change @@ -195,6 +195,15 @@ let slice a ~offset ~len =
195
195
done ;
196
196
result
197
197
198
+ let sliceToEnd a offset =
199
+ let lena = length a in
200
+ let ofs = if offset < 0 then max (lena + offset) 0 else offset in
201
+ let len = lena - ofs in
202
+ let result = makeUninitializedUnsafe len in
203
+ for i = 0 to len - 1 do
204
+ setUnsafe result i (getUnsafe a (ofs + i))
205
+ done ;
206
+ result
198
207
199
208
let fill a ~offset ~len v =
200
209
if len > 0 then
Original file line number Diff line number Diff line change @@ -257,6 +257,20 @@ val slice: 'a array -> offset:int -> len:int -> 'a array
257
257
]}
258
258
*)
259
259
260
+ val sliceToEnd : 'a array -> int -> 'a array
261
+ (* * [sliceToEnd xs offset] creates a new array with the elements of [xs] starting at [offset]
262
+
263
+ [offset] can be negative;and is evaluated as [length xs - offset]
264
+ [sliceToEnd xs -1] means get the last element as a singleton array
265
+
266
+ [sliceToEnd xs 0] will return a copy of the array
267
+
268
+ @example {[
269
+ sliceToEnd [|10;11;12;13;14;15;16|] 2 = [|12;13;14;15;16|];;
270
+ sliceToEnd [|10;11;12;13;14;15;16|] (-4) = [|13;14;15;16|];;
271
+ ]}
272
+ *)
273
+
260
274
261
275
external copy : 'a array -> (_ [@ bs.as 0 ]) -> 'a array = " slice" [@@ bs.send]
262
276
(* * [copy a]
You can’t perform that action at this time.
0 commit comments