This commit is contained in:
Jacques-Pascal Deplaix 2017-12-25 16:25:22 +00:00 committed by GitHub
commit 11b2c2e85c
2 changed files with 16 additions and 0 deletions

View file

@ -1136,6 +1136,17 @@ let remove_at_idx i l0 =
remove_at_idx (-4) [1;2;3;4] = [2;3;4]
*)
let rec remove_last = function
| [] | [_] -> []
| x::xs -> x::remove_last xs
(*$T
remove_last [] = []
remove_last [1] = []
remove_last [1; 2] = [1]
remove_last [1; 2; 3] = [1; 2]
*)
let range_by ~step i j =
let rec range i j acc =
if i=j then i::acc else range i (j-step) (j::acc)

View file

@ -265,6 +265,11 @@ val remove : ?eq:('a -> 'a -> bool) -> x:'a -> 'a t -> 'a t
@param eq equality function
@since 0.11 *)
val remove_last : 'a list -> 'a list
(** [remove_last l] removes the last element of [l]. If [l] is empty,
an empty list will be returned.
@since NEXT_RELEASE *)
val filter_map : ('a -> 'b option) -> 'a t -> 'b t
(** Map and remove elements at the same time *)