westonpace commented on a change in pull request #9643: URL: https://github.com/apache/arrow/pull/9643#discussion_r593081844
########## File path: cpp/src/arrow/util/vector.h ########## @@ -81,5 +84,53 @@ std::vector<T> FilterVector(std::vector<T> values, Predicate&& predicate) { return values; } +/// \brief Like MapVector, but where the function can fail. +template <typename Fn, typename From = internal::call_traits::argument_type<0, Fn>, + typename To = typename internal::call_traits::return_type<Fn>::ValueType> +Result<std::vector<To>> MaybeMapVector(Fn map, const std::vector<From>& src) { + std::vector<To> out; + out.reserve(src.size()); + ARROW_RETURN_NOT_OK( + MaybeTransform(src.begin(), src.end(), std::back_inserter(out), map)); + return out; +} + +template <typename Fn, typename From = internal::call_traits::argument_type<0, Fn>, + typename To = typename internal::call_traits::return_type<Fn>> +std::vector<To> MapVector(Fn map, const std::vector<From>& source) { Review comment: Done. ########## File path: cpp/src/arrow/util/vector.h ########## @@ -81,5 +84,53 @@ std::vector<T> FilterVector(std::vector<T> values, Predicate&& predicate) { return values; } +/// \brief Like MapVector, but where the function can fail. +template <typename Fn, typename From = internal::call_traits::argument_type<0, Fn>, + typename To = typename internal::call_traits::return_type<Fn>::ValueType> +Result<std::vector<To>> MaybeMapVector(Fn map, const std::vector<From>& src) { + std::vector<To> out; + out.reserve(src.size()); + ARROW_RETURN_NOT_OK( + MaybeTransform(src.begin(), src.end(), std::back_inserter(out), map)); + return out; +} + +template <typename Fn, typename From = internal::call_traits::argument_type<0, Fn>, + typename To = typename internal::call_traits::return_type<Fn>> +std::vector<To> MapVector(Fn map, const std::vector<From>& source) { + std::vector<To> out; + out.reserve(source.size()); + std::transform(source.begin(), source.end(), std::back_inserter(out), map); + return out; +} + +template <typename T> +std::vector<T> FlattenVectors(const std::vector<std::vector<T>> vecs) { Review comment: Done. ---------------------------------------------------------------- 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