westonpace commented on a change in pull request #9607: URL: https://github.com/apache/arrow/pull/9607#discussion_r605521628
########## File path: cpp/src/arrow/util/async_generator.h ########## @@ -1029,6 +1102,65 @@ AsyncGenerator<T> MakeConcatenatedGenerator(AsyncGenerator<AsyncGenerator<T>> so return MergedGenerator<T>(std::move(source), 1); } +template <typename T> +struct Enumerated { + util::optional<T> value; + int index; + bool last; +}; + +template <typename T> +struct IterationTraits<Enumerated<T>> { + static Enumerated<T> End() { return Enumerated<T>{{}, -1, false}; } + static bool IsEnd(const Enumerated<T>& val) { return !val.value.has_value(); } +}; + +template <typename T> +class EnumeratingGenerator { + public: + EnumeratingGenerator(AsyncGenerator<T> source, T initial_value) + : state_(std::make_shared<State>(std::move(source), std::move(initial_value))) {} + + Future<Enumerated<T>> operator()() { Review comment: Yeah, if we could somehow know up front how many scan tasks is in a fragment or how many record batches are in a scan task then this could be simplified. However, I'm not sure we can safely make that assumption. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org