mirror of
https://github.com/Naios/continuable.git
synced 2025-12-07 17:26:47 +08:00
Implement flatten as transform
This commit is contained in:
parent
0eb272a46f
commit
04539ba638
@ -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.
|
||||
|
||||
@ -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__
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user