diff --git a/Libs/Hopac/Stream.fs b/Libs/Hopac/Stream.fs index f69608a5..aac2cbf0 100644 --- a/Libs/Hopac/Stream.fs +++ b/Libs/Hopac/Stream.fs @@ -281,24 +281,20 @@ module Stream = let ambAll (xxs: Stream<#Stream<_>>) = joinWith amb' xxs - let rec mergeAll' (streams: Stream<'x> option) (producer: Stream> option) : Stream<'x> = - match streams, producer with - | None, Some p -> - p ^=> function Nil -> mergeAll' None None - | Cons (x, xs) -> mergeAll' (Some x) (Some xs) - |> memo - | Some s, None -> - s ^=> function Cons (x, xs) -> consj x (mergeAll' (Some xs) producer) - | Nil -> mergeAll' None producer :> _ - |> memo - | Some s, Some p -> - Alt.choose [ s ^=> function Cons (x, xs) -> consj x (mergeAll' (Some xs) producer) - | Nil -> mergeAll' None producer :> _ - p ^=> function Cons (x, xs) -> mergeAll' (merge s x |> Some) (Some xs) - | Nil -> mergeAll' streams None ] |> memo - | None, None -> memo nilj - - let mergeAll producer = mergeAll' None (Some producer) + let rec mergeAll' (combined: Stream<'x>) (producer: Stream>) : Stream<'x> = + combined ^=> function + | Nil -> producer >>= function + | Nil -> nilj + | Cons (x, xs) -> mergeAll' x xs :> _ + | Cons (v, vs) -> consj v (mergeAll' vs producer) + <|> producer ^=> function + | Nil -> combined >>= function + | Nil -> nilj + | Cons (v, vs) -> consj v (mergeAll' vs nil) + | Cons (x, xs) -> mergeAll' (merge combined x) xs :> _ + |> memo + + let mergeAll producer = mergeAll' nil producer let appendAll (xxs: Stream<#Stream<_>>) = joinWith append' xxs