I agree that it would be nice to factorize them. I think we can introduce the new interface with duplicated code now and delay any refactoring, but if you disagree we can block the PR until it is done.
(it is a shame that C++ coroutines aren't better, it would be so much more readable to implement this with for_each_simplex + yield)
Originally posted by @mglisse in #1229 (comment)