Add an operator| (pipe) for future folding and channels

This commit is contained in:
Denis Blank 2017-10-04 03:17:26 +02:00
parent 09bae47e09
commit 612aeef0c8
2 changed files with 19 additions and 11 deletions

View File

@ -323,6 +323,19 @@ public:
return std::move(*this).fail([](auto&&) {}); 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.
///
/// \returns See the corresponding continuable::then method for the
/// explanation of the return type.
///
/// \since version 2.0.0
template <typename T>
auto operator|(T&& right) && {
return std::move(*this).then(std::forward<T>(right));
}
/// Invokes both continuable_base objects parallel and calls the /// Invokes both continuable_base objects parallel and calls the
/// callback with the result of both continuable_base objects. /// callback with the result of both continuable_base objects.
/// ///

View File

@ -69,17 +69,12 @@ struct my_callable {
int main(int, char**) { int main(int, char**) {
http_request("github.com").flow(my_callable{}); http_request("github.com").flow(my_callable{});
http_request("github.com") http_request("github.com") | [](std::string) {
.then([](std::string) {
// ... // ...
return 0; return 0;
}) } | [] {
.fail([](std::error_condition) {
// ... // ...
}) };
.then([] {
// ...
});
http_request2("github.com") http_request2("github.com")
.then([](std::string) { .then([](std::string) {