From 6b17bb446a588dd992911bea68ab66d05857f979 Mon Sep 17 00:00:00 2001 From: Greta Yorsh <45005955+gretay-js@users.noreply.github.com> Date: Wed, 8 Jan 2025 14:33:01 +0000 Subject: [PATCH 1/3] Add function [DLL.for_all_i] --- utils/doubly_linked_list.ml | 8 ++++++++ utils/doubly_linked_list.mli | 2 ++ 2 files changed, 10 insertions(+) diff --git a/utils/doubly_linked_list.ml b/utils/doubly_linked_list.ml index b4a1f7c37ca..b13e05b07bf 100644 --- a/utils/doubly_linked_list.ml +++ b/utils/doubly_linked_list.ml @@ -340,6 +340,14 @@ let for_all t ~f = in aux t f t.first +let for_all_i t ~f = + let rec aux t f i curr = + match curr with + | Empty -> true + | Node node -> if f i node.value then aux t f (i + 1) node.next else false + in + aux t f 0 t.first + let to_list t = fold_right t ~f:(fun hd tl -> hd :: tl) ~init:[] let transfer ~to_ ~from () = diff --git a/utils/doubly_linked_list.mli b/utils/doubly_linked_list.mli index a2f406aff4b..e401d6cbe67 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_all_i : '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`. *) From 8b13905d1939fc1a0ed477018636c87f07d63ae6 Mon Sep 17 00:00:00 2001 From: Greta Yorsh <45005955+gretay-js@users.noreply.github.com> Date: Thu, 9 Jan 2025 13:44:08 +0000 Subject: [PATCH 2/3] Rename to [for_alli] to match existing [mapi] and [iteri] --- utils/doubly_linked_list.ml | 2 +- utils/doubly_linked_list.mli | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/doubly_linked_list.ml b/utils/doubly_linked_list.ml index b13e05b07bf..6ff90ab6f7f 100644 --- a/utils/doubly_linked_list.ml +++ b/utils/doubly_linked_list.ml @@ -340,7 +340,7 @@ let for_all t ~f = in aux t f t.first -let for_all_i t ~f = +let for_alli t ~f = let rec aux t f i curr = match curr with | Empty -> true diff --git a/utils/doubly_linked_list.mli b/utils/doubly_linked_list.mli index e401d6cbe67..32d572f7a73 100644 --- a/utils/doubly_linked_list.mli +++ b/utils/doubly_linked_list.mli @@ -78,7 +78,7 @@ val exists : 'a t -> f:('a -> bool) -> bool val for_all : 'a t -> f:('a -> bool) -> bool -val for_all_i : 'a t -> f:(int -> 'a -> bool) -> bool +val for_alli : 'a t -> f:(int -> 'a -> bool) -> bool val to_list : 'a t -> 'a list From 1c2f8f6ebd71716ea885dd886a5d12d2b0383729 Mon Sep 17 00:00:00 2001 From: Greta Yorsh <45005955+gretay-js@users.noreply.github.com> Date: Thu, 9 Jan 2025 13:45:33 +0000 Subject: [PATCH 3/3] Remove unused argument of [aux] in [DLL.for_all*] --- utils/doubly_linked_list.ml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/utils/doubly_linked_list.ml b/utils/doubly_linked_list.ml index 6ff90ab6f7f..7f6efc2ebd7 100644 --- a/utils/doubly_linked_list.ml +++ b/utils/doubly_linked_list.ml @@ -333,20 +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 t f i curr = + let rec aux f i curr = match curr with | Empty -> true - | Node node -> if f i node.value then aux t f (i + 1) node.next else false + | Node node -> if f i node.value then aux f (i + 1) node.next else false in - aux t f 0 t.first + aux f 0 t.first let to_list t = fold_right t ~f:(fun hd tl -> hd :: tl) ~init:[]