let split_and_merge ta tb ~split ~merge =
let name = sprintf "(merge <%s> <%s>)"
Option.(value ~default:"" (name ta))
Option.(value ~default:"" (name tb)) in
make_general ~name ()
~feed:(fun z ->
match split z with
| `left a -> feed ta a
| `right b -> feed tb b)
~stop:(fun () -> stop ta; stop tb)
~next:(fun () ->
match next ta with
| `output o -> `output (merge (`left o))
| `not_ready | `end_of_stream ->
begin match next tb with
| `output o -> `output (merge (`right o))
| `not_ready -> `not_ready
| `end_of_stream -> `end_of_stream
end)