aboutsummaryrefslogtreecommitdiff
path: root/clib
diff options
context:
space:
mode:
Diffstat (limited to 'clib')
-rw-r--r--clib/cList.ml3
-rw-r--r--clib/cList.mli4
2 files changed, 7 insertions, 0 deletions
diff --git a/clib/cList.ml b/clib/cList.ml
index de42886dcb..dc59ff2970 100644
--- a/clib/cList.ml
+++ b/clib/cList.ml
@@ -60,6 +60,7 @@ sig
val extend : bool list -> 'a -> 'a list -> 'a list
val count : ('a -> bool) -> 'a list -> int
val index : 'a eq -> 'a -> 'a list -> int
+ val safe_index : 'a eq -> 'a -> 'a list -> int option
val index0 : 'a eq -> 'a -> 'a list -> int
val fold_left_until : ('c -> 'a -> 'c CSig.until) -> 'c -> 'a list -> 'c
val fold_right_i : (int -> 'a -> 'b -> 'b) -> int -> 'a list -> 'b -> 'b
@@ -538,6 +539,8 @@ let rec index_f f x l n = match l with
let index f x l = index_f f x l 1
+let safe_index f x l = try Some (index f x l) with Not_found -> None
+
let index0 f x l = index_f f x l 0
(** {6 Folding} *)
diff --git a/clib/cList.mli b/clib/cList.mli
index 42fae5ed39..ed468cb977 100644
--- a/clib/cList.mli
+++ b/clib/cList.mli
@@ -155,6 +155,10 @@ sig
val index : 'a eq -> 'a -> 'a list -> int
(** [index] returns the 1st index of an element in a list (counting from 1). *)
+ val safe_index : 'a eq -> 'a -> 'a list -> int option
+ (** [safe_index] returns the 1st index of an element in a list (counting from 1)
+ and None otherwise. *)
+
val index0 : 'a eq -> 'a -> 'a list -> int
(** [index0] behaves as [index] except that it starts counting at 0. *)