Commits

Dmitry Grebeniuk  committed 5c29f80

itlist_anyresult_lasterror moved to ocaml-iteratees

  • Participants
  • Parent commits dea7d1a

Comments (0)

Files changed (2)

       It_IO.m (iteratee 'el 'a)
     ;
 
+    value itlist_anyresult_lasterror :
+      list (iteratee 'a 'b) -> iteratee 'a 'b
+    ;
+
     module Ops
      :
       sig

File dumbstreaming_it.ml

      =
       struct
 
-        exception Itlist_empty;
-
         module IO = I.It_IO;
 
         value ( & ) f x = f x;
         open I;
         value ( >>= ) m f = bindI f m;
  
-        value itlist_step_firstresult_lasterror
-          (lst : list (iteratee 'el 'a))
-          (s : stream 'el)
-         :
-          IO.m [= `First_result of (iteratee 'el 'a * stream 'el)
-               |  `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] ->
-                match hd with
-                [ (IE_done _) as it -> IO.return & `First_result (it, s)
-                | IE_cont ((Some _) as someerr) _ ->
-                    loop someerr acc tl
-                | IE_cont None k ->
-                    k 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'), _s) ->
-                        loop lasterropt [hd' :: acc] tl
-                    ]
-                ]
-            ]
-          in
-            if lst = []
-            then IO.return & `Last_error Itlist_empty
-            else loop None [] lst
+        value itlist_anyresult_lasterror = I.itlist_anyresult_lasterror
         ;
 
-        value get_any_done lst =
-          loop lst
-          where rec loop lst =
-            match lst with
-            [ [ ((IE_done _) as x) :: _ ] -> Some x
-            | [] -> None
-            | [ (IE_cont _ _) :: _ ] -> loop lst
-            ]
-        ;
-
-        value ie_contM k = IO.return (IE_cont None k, empty_stream)
-        ;
-
-
-        value itlist_anyresult_lasterror
-          (lst : list (iteratee 'el 'a))
-         :
-          iteratee 'el 'a
-         =
-          match get_any_done lst with
-          [ Some x -> x
-          | None -> ie_cont & step lst
-              where rec step lst s =
-                itlist_step_firstresult_lasterror lst s >>% fun
-                [ `First_result r -> IO.return r
-                | `Last_error e -> IO.error e
-                | `Cont [] -> assert False
-                | `Cont [it :: []] ->  IO.return (it, empty_stream)
-                | `Cont lst -> ie_contM & step lst
-                ]
-          ]
-        ;
-
-
         module type SIGNED_INT
          =
           sig