Implement flatten as transform

This commit is contained in:
Denis Blank 2017-10-04 04:10:50 +02:00
parent 0eb272a46f
commit 04539ba638
4 changed files with 20 additions and 15 deletions

View File

@ -324,17 +324,6 @@ public:
return std::forward<T>(transform)(std::move(*this));
}
/// Ignores all error which ocured until the point the function was called
///
/// \note This can be used to create a continuable which doesn't resolve
/// the continuation on errors.
///
/// \since version 2.0.0
/* TODO move to transforms
auto flat() && {
return std::move(*this).fail([](auto&&) {});
}*/
/// The pipe operator | is an alias for the continuable::then method.
///
/// \param right The argument on the right-hand side to connect.

View File

@ -55,12 +55,27 @@ namespace cti {
/// Otherwise this will yield a trap that causes application exit.
///
/// \since version 2.0.0
inline auto to_future() {
inline auto futurize() {
return [](auto&& continuable) {
using detail::transforms::as_future;
return as_future(std::forward<decltype(continuable)>(continuable));
};
}
/// Returns a transform that if applied to a continuable, it will ignores all
/// error which ocured until the point the transform was applied.
///
/// \returns Returns a continuable with the same signature as applied to.
///
/// \note This can be used to create a continuable which doesn't resolve
/// the continuation on errors.
///
/// \since version 2.0.0
inline auto flatten() {
return [](auto&& continuable) {
return std::forward<decltype(continuable)>(continuable).fail([](auto&&) {});
};
}
} // namespace cti
#endif // CONTINUABLE_TRANSFORMS_HPP_INCLUDED__

View File

@ -34,6 +34,7 @@
#include <future>
#include <continuable/detail/api.hpp>
#include <continuable/detail/base.hpp>
#include <continuable/detail/features.hpp>
#include <continuable/detail/hints.hpp>
#include <continuable/detail/types.hpp>

View File

@ -38,7 +38,7 @@ TYPED_TEST(single_dimension_tests, are_convertible_to_futures) {
};
{
auto future = this->supply().apply(cti::to_future());
auto future = this->supply().apply(cti::futurize());
ASSERT_TRUE(is_ready(future));
future.get();
}
@ -49,7 +49,7 @@ TYPED_TEST(single_dimension_tests, are_convertible_to_futures) {
// ...
return 0xFD;
})
.apply(cti::to_future());
.apply(cti::futurize());
ASSERT_TRUE(is_ready(future));
EXPECT_EQ(future.get(), 0xFD);
@ -63,7 +63,7 @@ TYPED_TEST(single_dimension_tests, are_convertible_to_futures) {
// ...
return canary;
})
.apply(cti::to_future());
.apply(cti::futurize());
ASSERT_TRUE(is_ready(future));
EXPECT_EQ(future.get(), canary);