From 612aeef0c832c5d43831c5201e6f2d90d9485700 Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Wed, 4 Oct 2017 03:17:26 +0200 Subject: [PATCH] Add an operator| (pipe) for future folding and channels --- include/continuable/continuable-base.hpp | 13 +++++++++++++ test/playground/test-playground.cpp | 17 ++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/include/continuable/continuable-base.hpp b/include/continuable/continuable-base.hpp index af9e89d..18c71c3 100644 --- a/include/continuable/continuable-base.hpp +++ b/include/continuable/continuable-base.hpp @@ -323,6 +323,19 @@ public: 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 + auto operator|(T&& right) && { + return std::move(*this).then(std::forward(right)); + } + /// Invokes both continuable_base objects parallel and calls the /// callback with the result of both continuable_base objects. /// diff --git a/test/playground/test-playground.cpp b/test/playground/test-playground.cpp index 3471e97..9716591 100644 --- a/test/playground/test-playground.cpp +++ b/test/playground/test-playground.cpp @@ -69,17 +69,12 @@ struct my_callable { int main(int, char**) { http_request("github.com").flow(my_callable{}); - http_request("github.com") - .then([](std::string) { - // ... - return 0; - }) - .fail([](std::error_condition) { - // ... - }) - .then([] { - // ... - }); + http_request("github.com") | [](std::string) { + // ... + return 0; + } | [] { + // ... + }; http_request2("github.com") .then([](std::string) {