Handle directories with no regular-file children
authorSiraaj Khandkar <siraaj@khandkar.net>
Wed, 14 Nov 2018 17:34:13 +0000 (12:34 -0500)
committerSiraaj Khandkar <siraaj@khandkar.net>
Wed, 14 Nov 2018 17:34:13 +0000 (12:34 -0500)
i.e. keep exploring child directories when no files remain to process

dups.ml

diff --git a/dups.ml b/dups.ml
index a1dca83..46e8b91 100644 (file)
--- a/dups.ml
+++ b/dups.ml
@@ -58,25 +58,16 @@ end = struct
             ()
       )
     in
             ()
       )
     in
-    let next_dir () =
-      match Queue.take dirs with
-      | exception Queue.Empty ->
-          ()
-      | dir ->
-          explore dir
-    in
-    let next_file () =
-      match Queue.take files with
-      | exception Queue.Empty ->
-          None
-      | file_path ->
-          Some file_path
-    in
     explore root;
     explore root;
-    Stream.create (fun () ->
-      next_dir ();
-      next_file ()
-    )
+    let rec next () =
+      match Queue.is_empty files, Queue.is_empty dirs with
+      | false, _     -> Some (Queue.take files)
+      | true , true  -> None
+      | true , false ->
+          explore (Queue.take dirs);
+          next ()
+    in
+    Stream.create next
 end
 
 type input =
 end
 
 type input =
This page took 0.017398 seconds and 4 git commands to generate.