diff --git a/infer/src/backend/iList.ml b/infer/src/backend/iList.ml index 1a534b3af..dccaf73e8 100644 --- a/infer/src/backend/iList.ml +++ b/infer/src/backend/iList.ml @@ -221,6 +221,17 @@ let rec find_map_opt f = function then e' else find_map_opt f l' +(** Like find_map_opt, but with indices *) +let find_mapi_opt (f : int -> 'a -> 'b option) l = + let rec find_mapi_opt_ f i = function + | [] -> None + | e :: l' -> + let e' = f i e in + if e' <> None + then e' + else find_mapi_opt_ f (i + 1) l' in + find_mapi_opt_ f 0 l + let to_string f l = let rec aux l = match l with diff --git a/infer/src/backend/iList.mli b/infer/src/backend/iList.mli index 850f1551e..a7d1c5edf 100644 --- a/infer/src/backend/iList.mli +++ b/infer/src/backend/iList.mli @@ -112,4 +112,7 @@ val map2 : ('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list (** Return the first non-None result found when applying f to elements of l *) val find_map_opt : ('a -> 'b option) -> 'a list -> 'b option +(** Like find_map_opt, but with indices *) +val find_mapi_opt : (int -> 'a -> 'b option) -> 'a list -> 'b option + val to_string : ('a -> string) -> 'a list -> string