Commits

Anonymous committed 55d541e

.

  • Participants
  • Parent commits 6dc4327

Comments (0)

Files changed (1)

File dumbstreaming_it.ml

  =
   sig
     type iteratee 'el 'a;
+    type err_msg = exn;
   end
 ;
 
   end
  =
   struct
+
+    module It_add
+     :
+      sig
+        value itlist_anyresult_lasterror
+         : list (iteratee 'a 'el) -> iteratee 'a 'el
+        ;
+      end
+     =
+      struct
+
+        exception Itlist_empty;
+
+        module IO = I.It_IO;
+
+        open It_Ops;
+        value ( >>% ) = IO.bind_rev;
+
+        open I;
+        value ( >>= ) = bindI;
+ 
+        value itlist_step_firstresult_lasterror lst s
+         : IO.m [= `First_result of iteratee 'el 'a * stream
+                |  `Last_error of err_msg
+                |  `Cont of list (iteratee 'el 'a)
+                ]
+         =
+          let rec loop lasterropt acc lst =
+            match lst with
+            [ [] ->
+                if acc = []
+                then
+                  match lasterropt with
+                  [ None -> assert False
+                  | Some err -> IO.return & `Last_error err
+                  ]
+                else
+                  IO.return & `Cont (List.rev acc)
+            | [hd :: tl] ->
+                hd s >>% fun
+                [ (IE_Done _, _) as r -> IO.return & `First_result r
+                | IE_Cont ((Some _) as someerr) _ -> loop someerr acc tl
+                | (IE_Cont None _) as hd' -> loop lasterropt [hd' :: acc] tl
+                ]
+          in
+            if lst = []
+            then IO.return & `Last_error Itlist_empty
+            else loop None [] hd tl
+        ;
+
+
+        value itlist_anyresult_lasterror
+         : list (iteratee 'a 'el) -> iteratee 'a 'el
+         =
+          если есть готовое, взять его, иначе ie_cont & ..
+        ;
+
+     end
+    ;
+
     value read _get_piece_iteratee _combine_pieces =
       failwith "not implemented"
     ;