summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2000-02-28 15:47:13 +0000
committerXavier Leroy <xavier.leroy@inria.fr>2000-02-28 15:47:13 +0000
commit8599d817b442f16c7e33bef3a2bc4f02a4371bb9 (patch)
tree6d3194fc3b9effd5a395914676c27190311fdb0a
parente32cdbb11eff7c830402881424d793661dc84891 (diff)
Ajout split_last
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2878 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--utils/misc.ml7
-rw-r--r--utils/misc.mli4
2 files changed, 10 insertions, 1 deletions
diff --git a/utils/misc.ml b/utils/misc.ml
index 529484692..390abd799 100644
--- a/utils/misc.ml
+++ b/utils/misc.ml
@@ -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
diff --git a/utils/misc.mli b/utils/misc.mli
index 969e97818..f3777c518 100644
--- a/utils/misc.mli
+++ b/utils/misc.mli
@@ -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