diff --git a/utils/doubly_linked_list.ml b/utils/doubly_linked_list.ml index b4a1f7c37ca..7f6efc2ebd7 100644 --- a/utils/doubly_linked_list.ml +++ b/utils/doubly_linked_list.ml @@ -333,12 +333,20 @@ let exists t ~f = aux t f t.first let for_all t ~f = - let rec aux t f curr = + let rec aux f curr = match curr with | Empty -> true - | Node node -> if f node.value then aux t f node.next else false + | Node node -> if f node.value then aux f node.next else false in - aux t f t.first + aux f t.first + +let for_alli t ~f = + let rec aux f i curr = + match curr with + | Empty -> true + | Node node -> if f i node.value then aux f (i + 1) node.next else false + in + aux f 0 t.first let to_list t = fold_right t ~f:(fun hd tl -> hd :: tl) ~init:[] diff --git a/utils/doubly_linked_list.mli b/utils/doubly_linked_list.mli index a2f406aff4b..32d572f7a73 100644 --- a/utils/doubly_linked_list.mli +++ b/utils/doubly_linked_list.mli @@ -78,6 +78,8 @@ val exists : 'a t -> f:('a -> bool) -> bool val for_all : 'a t -> f:('a -> bool) -> bool +val for_alli : 'a t -> f:(int -> 'a -> bool) -> bool + val to_list : 'a t -> 'a list (* Adds all of the elements of `from` to `to_`, and clears `from`. *)