Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function [DLL.for_all_i] #3442

Merged
merged 3 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions utils/doubly_linked_list.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
xclerc marked this conversation as resolved.
Show resolved Hide resolved
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 () =
Expand Down
2 changes: 2 additions & 0 deletions utils/doubly_linked_list.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
xclerc marked this conversation as resolved.
Show resolved Hide resolved

val to_list : 'a t -> 'a list

(* Adds all of the elements of `from` to `to_`, and clears `from`. *)
Expand Down
Loading