Merge pull request #170 from jpdeplaix/remove_at_neg_idx

Allow negative indexes in `CCList.remove_at_idx`
This commit is contained in:
Simon Cruanes 2017-12-25 17:25:15 +01:00 committed by GitHub
commit d8610646d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View file

@ -1121,12 +1121,19 @@ let remove_at_idx i l0 =
| y::l' ->
aux l' (y::acc) (i-1)
in
aux l0 [] i
if i < 0 then
aux l0 [] (List.length l0 + i)
else
aux l0 [] i
(*$T
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 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 =

View file

@ -359,7 +359,9 @@ val insert_at_idx : int -> 'a -> 'a t -> 'a t
val remove_at_idx : int -> 'a t -> 'a t
(** 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}