mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-18 16:46:40 -05:00
Add List.remove_last
This commit is contained in:
parent
e16d0ee27b
commit
1e55606323
2 changed files with 16 additions and 0 deletions
|
|
@ -1109,6 +1109,17 @@ let remove_at_idx i l0 =
|
||||||
remove_at_idx 5 [1;2;3;4] = [1;2;3;4]
|
remove_at_idx 5 [1;2;3;4] = [1;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 range_by ~step i j =
|
||||||
let rec range i j acc =
|
let rec range i j acc =
|
||||||
if i=j then i::acc else range i (j-step) (j::acc)
|
if i=j then i::acc else range i (j-step) (j::acc)
|
||||||
|
|
|
||||||
|
|
@ -261,6 +261,11 @@ val remove : ?eq:('a -> 'a -> bool) -> x:'a -> 'a t -> 'a t
|
||||||
@param eq equality function
|
@param eq equality function
|
||||||
@since 0.11 *)
|
@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
|
val filter_map : ('a -> 'b option) -> 'a t -> 'b t
|
||||||
(** Map and remove elements at the same time *)
|
(** Map and remove elements at the same time *)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue