let filter_compose left right ~destruct ~reconstruct =
let name =
sprintf "(part-compose <%s> <%s>)"
Option.(value ~default:"" (name left))
Option.(value ~default:"" (name right)) in
make_general ~name ()
~feed:(fun i -> feed left i)
~stop:(fun () -> stop left)
~next:(fun () ->
let call_right_next () =
begin match next right with
| `output o -> `output (reconstruct (`transformed o))
| `not_ready -> `not_ready
| `end_of_stream -> `end_of_stream
end
in
match next left with
| `output o ->
begin match destruct o with
| `transform y -> feed right y; call_right_next ()
| `bypass n -> `output (reconstruct (`bypassed n))
end
| `not_ready -> call_right_next ()
| `end_of_stream -> stop right; call_right_next ())