75 if (error_.has_value()) {
83 if (!result.has_value()) {
84 error_ = result.error();
85 }
else if (!result.value().has_value()) {
93 auto collect = [
this](
auto& values,
auto append,
94 auto finish) ->
Result<std::vector<T>> {
97 if (!result.has_value()) {
100 auto& value = result.value();
101 if (!value.has_value()) {
102 return finish(values);
104 append(values, value.value());
108 if constexpr (!std::is_move_constructible_v<T>) {
109 static_assert(std::is_copy_constructible_v<T>,
110 "Stream::ToVector requires T to be move- or copy-constructible");
115 std::deque<T> values;
117 values, [](
auto& destination,
const T& value) { destination.push_back(value); },
118 [](
const auto& source) {
119 return std::vector<T>(source.cbegin(), source.cend());
122 std::vector<T> values;
125 [](
auto& destination, T& value) {
126 destination.push_back(std::move_if_noexcept(value));
128 [](
auto& source) {
return std::move(source); });
140 bool finished_ =
false;
141 std::optional<Error> error_;
146 class VectorStream final :
public Stream<T> {
148 explicit VectorStream(std::vector<T> values) : values_(std::move(values)) {}
152 if (index_ == values_.size()) {
155 auto&& value = values_[index_++];
157 std::move_if_noexcept(value));
161 std::vector<T> values_;
164 return std::make_unique<VectorStream>(std::move(values));
A pull-based stream whose reads may fail.
Definition stream.h:47
virtual Result< std::optional< T > > NextImpl()=0
Produce the next value for Next().
Stream()=default
Construct a stream in its initial state.
virtual ~Stream()=default
Destroy this stream and release its producer resources.
static std::unique_ptr< Stream< T > > FromVector(std::vector< T > values)
Create a stream that owns and consumes the given values in order.
Definition stream.h:145
Stream(const Stream &)=delete
Streams cannot be copied.
Stream(Stream &&) noexcept=default
Move a stream and its terminal state.
Stream & operator=(const Stream &)=delete
Streams cannot be copy-assigned.
Result< std::vector< T > > ToVector()
Consume the remaining values into a vector.
Definition stream.h:92
Result< std::optional< T > > Next()
Return the next value, or std::nullopt when the stream is exhausted.
Definition stream.h:74
Definition expected.h:1199
Definition expected.h:246
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:34
Define Result, Status, and error helpers.