Ajout split_last

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2878 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Xavier Leroy 2000-02-28 15:47:13 +00:00
parent e32cdbb11e
commit 8599d817b4
2 changed files with 10 additions and 1 deletions

View File

@ -54,6 +54,13 @@ let rec list_remove x = function
| hd :: tl ->
if hd = x then tl else hd :: list_remove x tl
let rec split_last = function
[] -> assert false
| [x] -> ([], x)
| hd :: tl ->
let (lst, last) = split_last tl in
(hd :: lst, last)
(* Options *)
let may f = function

View File

@ -28,7 +28,9 @@ val replicate_list: 'a -> int -> 'a list
all identical to [elem]. *)
val list_remove: 'a -> 'a list -> 'a list
(* [list_remove x l] returns a copy of [l] with the first
element equal to [x] removed *)
element equal to [x] removed. *)
val split_last: 'a list -> 'a list * 'a
(* Return the last element and the other elements of the given list. *)
val may: ('a -> unit) -> 'a option -> unit
val may_map: ('a -> 'b) -> 'a option -> 'b option