mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 19:55:31 -05:00
Merge pull request #170 from jpdeplaix/remove_at_neg_idx
Allow negative indexes in `CCList.remove_at_idx`
This commit is contained in:
commit
d8610646d8
2 changed files with 11 additions and 2 deletions
|
|
@ -1121,12 +1121,19 @@ let remove_at_idx i l0 =
|
||||||
| y::l' ->
|
| y::l' ->
|
||||||
aux l' (y::acc) (i-1)
|
aux l' (y::acc) (i-1)
|
||||||
in
|
in
|
||||||
aux l0 [] i
|
if i < 0 then
|
||||||
|
aux l0 [] (List.length l0 + i)
|
||||||
|
else
|
||||||
|
aux l0 [] i
|
||||||
|
|
||||||
(*$T
|
(*$T
|
||||||
remove_at_idx 0 [1;2;3;4] = [2;3;4]
|
remove_at_idx 0 [1;2;3;4] = [2;3;4]
|
||||||
remove_at_idx 3 [1;2;3;4] = [1;2;3]
|
remove_at_idx 3 [1;2;3;4] = [1;2;3]
|
||||||
remove_at_idx 5 [1;2;3;4] = [1;2;3;4]
|
remove_at_idx 5 [1;2;3;4] = [1;2;3;4]
|
||||||
|
remove_at_idx (-1) [1;2;3;4] = [1;2;3]
|
||||||
|
remove_at_idx (-2) [1;2;3;4] = [1;2;4]
|
||||||
|
remove_at_idx (-3) [1;2;3;4] = [1;3;4]
|
||||||
|
remove_at_idx (-4) [1;2;3;4] = [2;3;4]
|
||||||
*)
|
*)
|
||||||
|
|
||||||
let range_by ~step i j =
|
let range_by ~step i j =
|
||||||
|
|
|
||||||
|
|
@ -359,7 +359,9 @@ val insert_at_idx : int -> 'a -> 'a t -> 'a t
|
||||||
|
|
||||||
val remove_at_idx : int -> 'a t -> 'a t
|
val remove_at_idx : int -> 'a t -> 'a t
|
||||||
(** Remove element at given index. Does nothing if the index is
|
(** Remove element at given index. Does nothing if the index is
|
||||||
too high. *)
|
too high.
|
||||||
|
If the index is negative, it will remove element starting from the end
|
||||||
|
of the list. *)
|
||||||
|
|
||||||
(** {2 Set Operators}
|
(** {2 Set Operators}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue