diff --git a/include/continuable/continuable-base.hpp b/include/continuable/continuable-base.hpp index c15e5d3..538afe0 100644 --- a/include/continuable/continuable-base.hpp +++ b/include/continuable/continuable-base.hpp @@ -324,17 +324,6 @@ public: return std::forward(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. diff --git a/include/continuable/continuable-transforms.hpp b/include/continuable/continuable-transforms.hpp index 7ab2672..4373154 100644 --- a/include/continuable/continuable-transforms.hpp +++ b/include/continuable/continuable-transforms.hpp @@ -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(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(continuable).fail([](auto&&) {}); + }; +} } // namespace cti #endif // CONTINUABLE_TRANSFORMS_HPP_INCLUDED__ diff --git a/include/continuable/detail/transforms.hpp b/include/continuable/detail/transforms.hpp index 7a9007a..3da527f 100644 --- a/include/continuable/detail/transforms.hpp +++ b/include/continuable/detail/transforms.hpp @@ -34,6 +34,7 @@ #include #include +#include #include #include #include diff --git a/test/unit-test/test-continuable-transforms.cpp b/test/unit-test/test-continuable-transforms.cpp index 0ec30a2..fe9c4d3 100644 --- a/test/unit-test/test-continuable-transforms.cpp +++ b/test/unit-test/test-continuable-transforms.cpp @@ -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);