diff --git a/README.md b/README.md index e09e95b4..2d8ba229 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,9 @@ For an example of how to depend on eventuals via Bazel in your own project you'l Most of the time you'll use higher-level ***combinators*** for composing eventuals together. This guide will start with more basic ones and work our way up to creating your own eventuals. -You ***compose*** eventuals together using an overloaded `operator|()`. You'll see some examples shortly. The syntax is similar to Bash "pipelines" and we reuse the term pipeline for eventuals as well. +You ***compose*** eventuals together using an overloaded `operator>>()`. You'll see some examples shortly. The syntax is similar to Bash "pipelines" (but instead of `|` we use `>>`) and we reuse the term pipeline for eventuals as well. + +Note that we use `operator>>()` instead of `operator|()` because it provides safer expression evaluation order in C++17 and on. See [this paper](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0145r3.pdf) for more details. Because the result type of a composed pipeline is not type-erased you'll use `auto` generously, e.g., as function return types. @@ -37,7 +39,7 @@ You must explicitly ***start*** an eventual in order for it to run. You'll only ```cpp auto e = AsynchronousFunction() - | Terminal() + >> Terminal() .start([](auto&& result) { // Eventual pipeline succeeded! }) @@ -99,7 +101,7 @@ Probably the most used of all the combinators, `Then()` continues a pipeline wit ```cpp http::Get("https://3rdparty.dev") - | Then([](http::Response&& response) { + >> Then([](http::Response&& response) { // Return an eventual that will automatically get started. return SomeAsynchronousFunction(response); }); @@ -109,7 +111,7 @@ You don't have to return an eventual in the callable passed to `Then()`, you can ```cpp http::Get("https:://3rdparty.dev") - | Then([](auto&& response) { + >> Then([](auto&& response) { // Return a value that will automatically get propagated. return response.code == 200; }); @@ -121,7 +123,7 @@ When you need to _conditionally_ continue using two differently typed eventuals ```cpp http::Get("https:://3rdparty.dev") - | Then([](auto&& response) { + >> Then([](auto&& response) { // Try for the 'www' host if we don't get a 200. return If(response.code != 200) .then(http::Get("https:://www.3rdparty.dev")) @@ -133,7 +135,7 @@ http::Get("https:://3rdparty.dev") ```cpp http::Get("https:://3rdparty.dev") - | Then([](auto&& response) { + >> Then([](auto&& response) { // Try for the 'www' host if we don't get a 200. return If(response.code != 200) .then(http::Get("https:://www.3rdparty.dev")) @@ -182,21 +184,21 @@ An `Expected:Of` *composes* with other eventuals exactly as though it is an e ```cpp ReadPersonFromFile(file) - | Then([](Person&& person) { + >> Then([](Person&& person) { return GetFullName(person); }) - | Then([](std::string&& full_name) { + >> Then([](std::string&& full_name) { ... }); ``` -Or you can compose an eventual with `|` which can be useful in cases where want the error to propagate: +Or you can compose an eventual with `>>` which can be useful in cases where want the error to propagate: ```cpp ReadPersonFromFile(file) - | Then(Let([](auto& person) { + >> Then(Let([](auto& person) { return GetFullName(person) - | Then([&](auto&& full_name) { + >> Then([&](auto&& full_name) { if (person.has_suffix) { return full_name + " " + person.suffix(); } else { @@ -213,7 +215,7 @@ Working with *asynchronous* code is a little complicated because there might be ```cpp auto GetBody(const std::string& uri) { return http::Get(uri) - | Then([](auto&& response) { + >> Then([](auto&& response) { return If(response.code == 200) .then(Just(response.body)) .otherwise(Raise("HTTP GET failed w/ code " + std::to_string(response.code))); @@ -226,7 +228,7 @@ But as we already saw `If()` is not _only_ useful for errors; it can also be use ```cpp auto GetOrRedirect(const std::string& uri, const std::string& redirect_uri) { return http::Get(uri) - | Then([redirect_uri](auto&& response) { + >> Then([redirect_uri](auto&& response) { // Redirect if 'Service Unavailable'. return If(response.code == 503) .then(http::get(redirect_uri)) @@ -244,11 +246,11 @@ Synchronization is just as necessary with asynchronous code as with synchronous Lock lock; AsynchronousFunction() - | Acquire(&lock) - | Then([](auto&& result) { + >> Acquire(&lock) + >> Then([](auto&& result) { // Protected by 'lock' ... }) - | Release(&lock); + >> Release(&lock); ``` This is often used when capturing `this` to use as part of some asynchronous computation. To simplify this common pattern you can extend your classes with `Synchronizable` and then use `Synchronized()`: @@ -282,14 +284,14 @@ class SomeAggregateSystem : public Synchronizable { return cooling_subsystem_initialized_ && safety_subsystem_initialized_; }) - | Then([](auto&& result) { + >> Then([](auto&& result) { // ... })); } auto InitializeCoolingSubsystem() { return CoolingSubsystemInitialization() - | Synchronized( + >> Synchronized( Then([this]() { cooling_subsystem_initialized_ = true; initialization_.Notify(); @@ -319,7 +321,7 @@ You can compose a `Task::Of` just like any other eventual as well: ```cpp auto e = Task::Of([]() { return Asynchronous(); }) - | Then([](int i) { + >> Then([](int i) { return stringify(i); }); ``` @@ -362,7 +364,7 @@ class DerivedAsynchronous : public Base { Task::Of Method() override { return []() { return AsynchronousFunction() - | Then([](bool condition) -> Expected::Of { + >> Then([](bool condition) -> Expected::Of { if (condition) { return Expected("success"); } else { @@ -494,7 +496,7 @@ Stream() ended(k); } }) - | Loop() + >> Loop() .context(0) .body([](auto& sum, auto& stream, auto&& value) { sum += value; @@ -519,10 +521,10 @@ Often times you'll want to perform some transformations on your stream. You can ```cpp Iterate({1, 2, 3, 4, 5}) - | Map([](int i) { + >> Map([](int i) { return i + 1; }) - | Reduce( + >> Reduce( /* sum = */ 0, [](auto& sum) { return Then([&](auto&& value) { @@ -538,8 +540,8 @@ Sometimes you'll have an infinite stream. You can loop over it infinitely by usi ```cpp SomeInfiniteStream() - | Map([](auto&& i) { return Foo(i); }) - | Loop(); // Infinitely loop. + >> Map([](auto&& i) { return Foo(i); }) + >> Loop(); // Infinitely loop. ``` ### `http` @@ -550,7 +552,7 @@ An HTTP `GET`: ```cpp http::Get("http://example.com") // Use 'https://' for TLS/SSL. - | Then([](http::Response&& response) { + >> Then([](http::Response&& response) { // ... }); ``` @@ -561,7 +563,7 @@ An HTTP `POST`: http::Post( "https://jsonplaceholder.typicode.com/posts", {{"first", "emily"}, {"last", "schneider"}}) - | Then([](auto&& response) { + >> Then([](auto&& response) { // ... }); ``` @@ -576,7 +578,7 @@ http::Client client = http::Client::Builder() client.Post( "https://jsonplaceholder.typicode.com/posts", {{"first", "emily"}, {"last", "schneider"}}) - | Then([](auto&& response) { + >> Then([](auto&& response) { // ... }); ``` @@ -591,7 +593,7 @@ client.Do( .header("key", "value") .header("another", "example") .Build()) - | Then([](auto&& response) { + >> Then([](auto&& response) { // ... }); ``` @@ -605,7 +607,7 @@ client.Do( .method(http::GET) .verify_peer(true) // Overrides client! .Build()) - | Then([](auto&& response) { + >> Then([](auto&& response) { // ... }); ``` @@ -629,7 +631,7 @@ http::Client client = http::Client::Builder() .Build(); client.Get("https://3rdparty.dev") - | Then([](auto&& response) { + >> Then([](auto&& response) { // ... }); ``` @@ -650,7 +652,7 @@ client.Do( .method(http::GET) .certificate(*certificate) .Build()) - | Then([](auto&& response) { + >> Then([](auto&& response) { // ... }); ``` diff --git a/eventuals/compose.h b/eventuals/compose.h index de4a16e5..dab6ff1c 100644 --- a/eventuals/compose.h +++ b/eventuals/compose.h @@ -102,20 +102,6 @@ struct Composed final { //////////////////////////////////////////////////////////////////////// -template < - typename Left, - typename Right, - std::enable_if_t< - std::conjunction_v< - HasValueFrom, - HasValueFrom>, - int> = 0> -[[nodiscard]] auto operator|(Left left, Right right) { - return Composed{std::move(left), std::move(right)}; -} - -//////////////////////////////////////////////////////////////////////// - template < typename Left, typename Right, diff --git a/eventuals/concurrent-ordered.h b/eventuals/concurrent-ordered.h index 2fa0fd72..67b6028c 100644 --- a/eventuals/concurrent-ordered.h +++ b/eventuals/concurrent-ordered.h @@ -247,23 +247,23 @@ template return Map([i = 1](auto&& value) mutable { return std::make_tuple(i++, std::forward(value)); }) - | Concurrent([f = std::move(f)]() { + >> Concurrent([f = std::move(f)]() { return FlatMap([&f, j = 1](auto&& tuple) mutable { j = std::get<0>(tuple); return Iterate({std::move(std::get<1>(tuple))}) - | f() - | Map([j](auto&& value) { + >> f() + >> Map([j](auto&& value) { return std::make_tuple(j, std::move(value)); }) // A special 'ConcurrentOrderedAdaptor()' allows us to handle // the case when 'f()' has ended so we can propagate down to // 'ReorderAdaptor()' that all elements for the 'i'th tranche // of values has been emitted. - | ConcurrentOrderedAdaptor(); + >> ConcurrentOrderedAdaptor(); }); }) // Handles the reordering of values by the propagated indexes. - | ReorderAdaptor(); + >> ReorderAdaptor(); } ///////////////////////////////////////////////////////////////////// diff --git a/eventuals/concurrent.h b/eventuals/concurrent.h index b6174e5c..0d057646 100644 --- a/eventuals/concurrent.h +++ b/eventuals/concurrent.h @@ -337,7 +337,7 @@ struct _Concurrent final { notify_done_(); } })) - | Terminal(); + >> Terminal(); } // Returns an eventual which will wait for the upstream stream to @@ -358,10 +358,10 @@ struct _Concurrent final { || !fibers_done_; }; })) - | Then([callback = std::move(callback)]() mutable { + >> Then([callback = std::move(callback)]() mutable { callback(); }) - | Terminal(); + >> Terminal(); } // Returns an eventual which handles when "downstream" requests @@ -398,7 +398,7 @@ struct _Concurrent final { // like function that you can call _before_ calling // 'Done()' on the 'Concurrent()'. })) - | Terminal(); + >> Terminal(); } // Head of linked list of fibers. @@ -456,14 +456,14 @@ struct _Concurrent final { // down below even though we know we only have a // single 'arg' to iterate from the top. Iterate({std::move(arg)}) - | f_()) - | Synchronized(Map([this](auto&& value) { + >> f_()) + >> Synchronized(Map([this](auto&& value) { values_.push_back(std::forward(value)); notify_egress_(); })) - | Loop() - | FiberEpilogue(fiber) - | Terminal(); + >> Loop() + >> FiberEpilogue(fiber) + >> Terminal(); } // Returns an upcasted 'TypeErasedFiber' from our typeful 'Fiber'. @@ -498,7 +498,7 @@ struct _Concurrent final { [[nodiscard]] auto Ingress() { return Map(Let([this](Arg_& arg) { return CreateOrReuseFiber() - | Then([&](TypeErasedFiber* fiber) { + >> Then([&](TypeErasedFiber* fiber) { // A nullptr indicates that we should tell // upstream we're "done" because something // failed or an interrupt was received. @@ -511,10 +511,10 @@ struct _Concurrent final { return done; }); })) - | Until([](bool done) { return done; }) - | Loop() // Eagerly try to get next value to run concurrently! - | IngressEpilogue() - | Terminal(); + >> Until([](bool done) { return done; }) + >> Loop() // Eagerly try to get next value to run concurrently! + >> IngressEpilogue() + >> Terminal(); } // Returns an eventual which implements the logic for handling @@ -534,7 +534,7 @@ struct _Concurrent final { // Need to check for an exception _before_ // 'Until()' because we have no way of hooking // into "ended" after 'Until()'. - | Map([this]() { + >> Map([this]() { return Eventual>() .start([this](auto& k) { if (exception_ && upstream_done_ && fibers_done_) { @@ -556,10 +556,10 @@ struct _Concurrent final { } }); })) - | Until([](std::optional& value) { + >> Until([](std::optional& value) { return !value; }) - | Map([](std::optional&& value) { + >> Map([](std::optional&& value) { CHECK(value); return std::move(*value); }); diff --git a/eventuals/do-all.h b/eventuals/do-all.h index def61af1..ac6baf96 100644 --- a/eventuals/do-all.h +++ b/eventuals/do-all.h @@ -46,81 +46,81 @@ struct _DoAll final { [[nodiscard]] auto BuildEventual(Eventual eventual) { return Build( std::move(eventual) - | Terminal() - .start([this](auto&&... value) { - if constexpr (sizeof...(value) != 0) { - std::get(values_) - .template emplace...>( - std::forward(value)...); - } else { - // Assume it's void, std::monostate will be the default. - } - if (counter_.fetch_sub(1) == 1) { - // You're the last eventual so call the continuation. - std::optional exception = - GetExceptionIfExists(); - - if (exception) { - try { - std::rethrow_exception(*exception); - } catch (const StoppedException&) { - k_.Stop(); - } catch (...) { - k_.Fail(std::current_exception()); - } - } else { - k_.Start(GetTupleOfValues()); - } - } - }) - .fail([this](auto&&... errors) { - std::get(values_) - .template emplace( - make_exception_ptr_or_forward( - std::forward(errors)...)); - if (counter_.fetch_sub(1) == 1) { - // You're the last eventual so call the continuation. - std::optional exception = - GetExceptionIfExists(); - - CHECK(exception); - try { - std::rethrow_exception(*exception); - } catch (const StoppedException&) { - k_.Stop(); - } catch (...) { - k_.Fail(std::current_exception()); - } - } else { - // Interrupt the remaining eventuals so we can - // propagate the failure. - interrupt_.Trigger(); - } - }) - .stop([this]() { - std::get(values_) - .template emplace( - std::make_exception_ptr( - StoppedException())); - if (counter_.fetch_sub(1) == 1) { - // You're the last eventual so call the continuation. - std::optional exception = - GetExceptionIfExists(); - - CHECK(exception); - try { - std::rethrow_exception(*exception); - } catch (const StoppedException&) { - k_.Stop(); - } catch (...) { - k_.Fail(std::current_exception()); - } - } else { - // Interrupt the remaining eventuals so we can - // propagate the stop. - interrupt_.Trigger(); - } - })); + >> Terminal() + .start([this](auto&&... value) { + if constexpr (sizeof...(value) != 0) { + std::get(values_) + .template emplace...>( + std::forward(value)...); + } else { + // Assume it's void, std::monostate will be the default. + } + if (counter_.fetch_sub(1) == 1) { + // You're the last eventual so call the continuation. + std::optional exception = + GetExceptionIfExists(); + + if (exception) { + try { + std::rethrow_exception(*exception); + } catch (const StoppedException&) { + k_.Stop(); + } catch (...) { + k_.Fail(std::current_exception()); + } + } else { + k_.Start(GetTupleOfValues()); + } + } + }) + .fail([this](auto&&... errors) { + std::get(values_) + .template emplace( + make_exception_ptr_or_forward( + std::forward(errors)...)); + if (counter_.fetch_sub(1) == 1) { + // You're the last eventual so call the continuation. + std::optional exception = + GetExceptionIfExists(); + + CHECK(exception); + try { + std::rethrow_exception(*exception); + } catch (const StoppedException&) { + k_.Stop(); + } catch (...) { + k_.Fail(std::current_exception()); + } + } else { + // Interrupt the remaining eventuals so we can + // propagate the failure. + interrupt_.Trigger(); + } + }) + .stop([this]() { + std::get(values_) + .template emplace( + std::make_exception_ptr( + StoppedException())); + if (counter_.fetch_sub(1) == 1) { + // You're the last eventual so call the continuation. + std::optional exception = + GetExceptionIfExists(); + + CHECK(exception); + try { + std::rethrow_exception(*exception); + } catch (const StoppedException&) { + k_.Stop(); + } catch (...) { + k_.Fail(std::current_exception()); + } + } else { + // Interrupt the remaining eventuals so we can + // propagate the stop. + interrupt_.Trigger(); + } + })); } std::tuple< diff --git a/eventuals/executor.h b/eventuals/executor.h index 9bfb79b2..60a172c4 100644 --- a/eventuals/executor.h +++ b/eventuals/executor.h @@ -37,7 +37,7 @@ class Executor final wait_until_finished_(&lock()), executor_(this->Borrow([this]() { return pipe_.Read() - | Concurrent([this]() { + >> Concurrent([this]() { return Map([this](E_ e) { // NOTE: we do 'RescheduleAfter()' here so that we // make sure we don't end up borrowing any @@ -47,19 +47,19 @@ class Executor final return RescheduleAfter(std::move(e)) // NOTE: returning 'std::monostate' since // 'Concurrent' does not yet support 'void'. - | Just(std::monostate{}) - | Catch() - .raised( - [this](std::exception&& e) { - EVENTUALS_LOG(1) - << "Executor '" << name_ - << "' caught: " << e.what(); - return std::monostate{}; - }); + >> Just(std::monostate{}) + >> Catch() + .raised( + [this](std::exception&& e) { + EVENTUALS_LOG(1) + << "Executor '" << name_ + << "' caught: " << e.what(); + return std::monostate{}; + }); }); }) - | Loop() - | Synchronized( + >> Loop() + >> Synchronized( Eventual() .start([this](auto& k) { finished_ = true; diff --git a/eventuals/expected.h b/eventuals/expected.h index f14d90c8..81a31755 100644 --- a/eventuals/expected.h +++ b/eventuals/expected.h @@ -120,30 +120,6 @@ using tl::make_unexpected; //////////////////////////////////////////////////////////////////////// -template < - typename Left, - typename T, - typename E, - std::enable_if_t::value, int> = 0> -[[nodiscard]] auto operator|(Left left, tl::expected&& expected) { - return std::move(left) - | ExpectedToEventual(std::move(expected)); -} - -//////////////////////////////////////////////////////////////////////// - -template < - typename Right, - typename T, - typename E, - std::enable_if_t::value, int> = 0> -[[nodiscard]] auto operator|(tl::expected&& expected, Right right) { - return ExpectedToEventual(std::move(expected)) - | std::move(right); -} - -//////////////////////////////////////////////////////////////////////// - template < typename Left, typename T, @@ -151,7 +127,7 @@ template < std::enable_if_t::value, int> = 0> [[nodiscard]] auto operator>>(Left left, tl::expected&& expected) { return std::move(left) - | ExpectedToEventual(std::move(expected)); + >> ExpectedToEventual(std::move(expected)); } //////////////////////////////////////////////////////////////////////// @@ -163,7 +139,7 @@ template < std::enable_if_t::value, int> = 0> [[nodiscard]] auto operator>>(tl::expected&& expected, Right right) { return ExpectedToEventual(std::move(expected)) - | std::move(right); + >> std::move(right); } //////////////////////////////////////////////////////////////////////// diff --git a/eventuals/finally.h b/eventuals/finally.h index c60afe83..9e629050 100644 --- a/eventuals/finally.h +++ b/eventuals/finally.h @@ -63,7 +63,7 @@ struct _Finally final { template [[nodiscard]] auto Finally(F f) { return _Finally::Composable() - | Then(std::move(f)); + >> Then(std::move(f)); } //////////////////////////////////////////////////////////////////////// diff --git a/eventuals/foreach.h b/eventuals/foreach.h index 5364cfc2..e24a529a 100644 --- a/eventuals/foreach.h +++ b/eventuals/foreach.h @@ -13,8 +13,8 @@ namespace eventuals { template [[nodiscard]] auto Foreach(E e, F f) { return std::move(e) - | Map(std::move(f)) - | Loop(); + >> Map(std::move(f)) + >> Loop(); } //////////////////////////////////////////////////////////////////////// diff --git a/eventuals/grpc/client.h b/eventuals/grpc/client.h index db10b7fe..1d9e857b 100644 --- a/eventuals/grpc/client.h +++ b/eventuals/grpc/client.h @@ -479,10 +479,10 @@ class Client { std::string name, std::optional host = std::nullopt) { return Context() - | Then([this, - name = std::move(name), - host = std::move(host)]( - ::grpc::ClientContext* context) mutable { + >> Then([this, + name = std::move(name), + host = std::move(host)]( + ::grpc::ClientContext* context) mutable { return Call( std::move(name), context, diff --git a/eventuals/grpc/server.cc b/eventuals/grpc/server.cc index 4a710788..6c63c859 100644 --- a/eventuals/grpc/server.cc +++ b/eventuals/grpc/server.cc @@ -158,8 +158,8 @@ Server::Server( return Repeat([&]() mutable { context = std::make_unique(); return RequestCall(context.get(), cq) - | Lookup(context.get()) - | Conditional( + >> Lookup(context.get()) + >> Conditional( [](auto* endpoint) { return endpoint != nullptr; }, @@ -171,20 +171,20 @@ Server::Server( return Unimplemented(context.release()); }); }) - | Loop() - | Catch() - .raised( - [this](std::exception&& e) { - EVENTUALS_GRPC_LOG(1) - << "Failed to accept a call: " - << e.what() << "; shutting down"; - - // TODO(benh): refactor so we only call - // 'ShutdownEndpoints()' once on server - // shutdown, not for each worker (which - // should be harmless but unnecessary). - return ShutdownEndpoints(); - }); + >> Loop() + >> Catch() + .raised( + [this](std::exception&& e) { + EVENTUALS_GRPC_LOG(1) + << "Failed to accept a call: " + << e.what() << "; shutting down"; + + // TODO(benh): refactor so we only call + // 'ShutdownEndpoints()' once on server + // shutdown, not for each worker (which + // should be harmless but unnecessary). + return ShutdownEndpoints(); + }); }); }); diff --git a/eventuals/grpc/server.h b/eventuals/grpc/server.h index b289bf01..56c1b4c8 100644 --- a/eventuals/grpc/server.h +++ b/eventuals/grpc/server.h @@ -41,7 +41,7 @@ namespace grpc { //////////////////////////////////////////////////////////////////////// -using eventuals::operator|; +using eventuals::operator>>; //////////////////////////////////////////////////////////////////////// @@ -680,11 +680,11 @@ inline auto Server::Insert(std::unique_ptr&& endpoint) { inline auto Server::ShutdownEndpoints() { return Synchronized(Then([this]() { return Iterate(endpoints_) - | Map([](auto& entry) { + >> Map([](auto& entry) { auto& [_, endpoint] = entry; return endpoint->Shutdown(); }) - | Loop(); + >> Loop(); })); } @@ -729,14 +729,14 @@ auto Server::Accept(std::string name, std::string host) { // 'Insert()' fails so we won't be using a dangling pointer. auto Dequeue = [endpoint = endpoint.get()]() { return endpoint->Dequeue() - | Map([](auto&& context) { + >> Map([](auto&& context) { return ServerCall(std::move(context)); }); }; return Validate(name) - | Insert(std::move(endpoint)) - | Dequeue(); + >> Insert(std::move(endpoint)) + >> Dequeue(); } //////////////////////////////////////////////////////////////////////// @@ -745,7 +745,7 @@ auto Server::Accept(std::string name, std::string host) { template [[nodiscard]] auto UnaryPrologue(ServerCall& call) { return call.Reader().Read() - | Head(); // Only get the first request. + >> Head(); // Only get the first request. } //////////////////////////////////////////////////////////////////////// @@ -758,34 +758,34 @@ template return call.Writer().WriteLast( std::forward(response)); }) - | Just(::grpc::Status::OK) - | Catch() - .raised([](std::exception&& e) { - return ::grpc::Status(::grpc::UNKNOWN, e.what()); - }) - | Then([&](::grpc::Status status) { + >> Just(::grpc::Status::OK) + >> Catch() + .raised([](std::exception&& e) { + return ::grpc::Status(::grpc::UNKNOWN, e.what()); + }) + >> Then([&](::grpc::Status status) { return call.Finish(status) - | Finally([&](expected&& e) { + >> Finally([&](expected&& e) { return If(e.has_value()) .no([e = std::move(e), &call]() { return Raise(std::move(e.error())) - | Catch() - .raised( - [&call](std::exception&& e) { - EVENTUALS_GRPC_LOG(1) - << "Finishing call (" - << call.context() << ")" - << " for host = " - << call.context()->host() - << " and path = " - << call.context() - ->method() - << " failed: " - << e.what(); - }); + >> Catch() + .raised( + [&call](std::exception&& e) { + EVENTUALS_GRPC_LOG(1) + << "Finishing call (" + << call.context() << ")" + << " for host = " + << call.context()->host() + << " and path = " + << call.context() + ->method() + << " failed: " + << e.what(); + }); }) .yes([]() { return Just(); }) - | call.WaitForDone(); + >> call.WaitForDone(); }); }); } @@ -799,35 +799,35 @@ template return Map([&](auto&& response) { return call.Writer().Write(response); }) - | Loop() - | Just(::grpc::Status::OK) - | Catch() - .raised([](std::exception&& e) { - return ::grpc::Status(::grpc::UNKNOWN, e.what()); - }) - | Then([&](::grpc::Status status) { + >> Loop() + >> Just(::grpc::Status::OK) + >> Catch() + .raised([](std::exception&& e) { + return ::grpc::Status(::grpc::UNKNOWN, e.what()); + }) + >> Then([&](::grpc::Status status) { return call.Finish(status) - | Finally([&](expected&& e) { + >> Finally([&](expected&& e) { return If(e.has_value()) .no([e = std::move(e), &call]() { return Raise(std::move(e.error())) - | Catch() - .raised( - [&call](std::exception&& e) { - EVENTUALS_GRPC_LOG(1) - << "Finishing call (" - << call.context() << ")" - << " for host = " - << call.context()->host() - << " and path = " - << call.context() - ->method() - << " failed: " - << e.what(); - }); + >> Catch() + .raised( + [&call](std::exception&& e) { + EVENTUALS_GRPC_LOG(1) + << "Finishing call (" + << call.context() << ")" + << " for host = " + << call.context()->host() + << " and path = " + << call.context() + ->method() + << " failed: " + << e.what(); + }); }) .yes([]() { return Just(); }) - | call.WaitForDone(); + >> call.WaitForDone(); }); }); } diff --git a/eventuals/let.h b/eventuals/let.h index 2fff31da..fc61070a 100644 --- a/eventuals/let.h +++ b/eventuals/let.h @@ -24,9 +24,9 @@ namespace eventuals { // callable. For example, you can use 'Let()' with 'Then()': // // SomethingThatReturnsAFoo() -// | Then(Let([](auto& foo) { +// >> Then(Let([](auto& foo) { // return DoSomethingAsynchronouslyWithFoo(foo) -// | Then([&]() { +// >> Then([&]() { // return DoSomethingSynchronouslyWithFoo(foo); // }); // })); diff --git a/eventuals/lock.h b/eventuals/lock.h index 410c3aad..1820d25c 100644 --- a/eventuals/lock.h +++ b/eventuals/lock.h @@ -820,8 +820,8 @@ class Synchronizable { template [[nodiscard]] auto Synchronized(E e) { return Acquire(&lock_) - | std::move(e) - | Release(&lock_); + >> std::move(e) + >> Release(&lock_); } template diff --git a/eventuals/map.h b/eventuals/map.h index 7422d69c..4fb23266 100644 --- a/eventuals/map.h +++ b/eventuals/map.h @@ -122,7 +122,7 @@ struct _Map final { // simpler composition graph to lessen the template instantiation // load and execution (i.e., graph walk/traversal) at runtime. if constexpr (Traits::exists) { - auto e = std::move(e_) | std::move(k.e_); + auto e = std::move(e_) >> std::move(k.e_); using E = decltype(e); return Continuation( std::move(k.k_), diff --git a/eventuals/pipe.h b/eventuals/pipe.h index a0591d97..ac4b262a 100644 --- a/eventuals/pipe.h +++ b/eventuals/pipe.h @@ -35,13 +35,13 @@ class Pipe final : public Synchronizable { [[nodiscard]] auto Read() { return Repeat() - | Synchronized( + >> Synchronized( Map([this]() { return has_values_or_closed_.Wait([this]() { return values_.empty() && !is_closed_; }); }) - | Map([this]() { + >> Map([this]() { if (!values_.empty()) { auto value = std::move(values_.front()); values_.pop_front(); @@ -51,10 +51,10 @@ class Pipe final : public Synchronizable { return std::optional(); } })) - | Until([](auto& value) { + >> Until([](auto& value) { return !value.has_value(); }) - | Map([](auto&& value) { + >> Map([](auto&& value) { CHECK(value); // NOTE: need to use 'Just' here in case 'T' is an // eventual otherwise we'll try and compose with it here! diff --git a/eventuals/promisify.h b/eventuals/promisify.h index 337608ef..13573065 100644 --- a/eventuals/promisify.h +++ b/eventuals/promisify.h @@ -39,25 +39,25 @@ template // rescheduling again because when we terminate we're done! return Reschedule(context->Borrow()); }) - | std::move(e) - | Terminal() - .context(std::move(promise)) - .start([](auto& promise, auto&&... values) { - static_assert( - sizeof...(values) == 0 || sizeof...(values) == 1, - "'Promisify()' only supports 0 or 1 value, but found > 1"); - promise.set_value(std::forward(values)...); - }) - .fail([](auto& promise, auto&& error) { - promise.set_exception( - make_exception_ptr_or_forward( - std::forward(error))); - }) - .stop([](auto& promise) { - promise.set_exception( - std::make_exception_ptr( - StoppedException())); - })); + >> std::move(e) + >> Terminal() + .context(std::move(promise)) + .start([](auto& promise, auto&&... values) { + static_assert( + sizeof...(values) == 0 || sizeof...(values) == 1, + "'Promisify()' only supports 0 or 1 value, but found > 1"); + promise.set_value(std::forward(values)...); + }) + .fail([](auto& promise, auto&& error) { + promise.set_exception( + make_exception_ptr_or_forward( + std::forward(error))); + }) + .stop([](auto& promise) { + promise.set_exception( + std::make_exception_ptr( + StoppedException())); + })); return std::make_tuple(std::move(future), std::move(k)); } diff --git a/eventuals/repeat.h b/eventuals/repeat.h index 2a1f91d6..92f77c28 100644 --- a/eventuals/repeat.h +++ b/eventuals/repeat.h @@ -84,7 +84,7 @@ template !HasValueFrom::value, "'Repeat' expects a callable (e.g., a lambda) not an eventual"); - return _Repeat::Composable{} | Map(std::move(f)); + return _Repeat::Composable{} >> Map(std::move(f)); } [[nodiscard]] inline auto Repeat() { diff --git a/eventuals/scheduler.h b/eventuals/scheduler.h index 496c0e85..e4d700b4 100644 --- a/eventuals/scheduler.h +++ b/eventuals/scheduler.h @@ -343,7 +343,7 @@ template [[nodiscard]] auto RescheduleAfter(E e) { return Closure([e = std::move(e)]() mutable { return std::move(e) - | Reschedule(Scheduler::Context::Get().reborrow()); + >> Reschedule(Scheduler::Context::Get().reborrow()); }); } @@ -452,8 +452,8 @@ struct _Preempt final { adapted_.emplace( (Reschedule(context_.Borrow()) - | std::move(e_) - | Reschedule(std::move(previous))) + >> std::move(e_) + >> Reschedule(std::move(previous))) .template k(std::move(k_))); if (interrupt_ != nullptr) { @@ -471,8 +471,8 @@ struct _Preempt final { using Adapted_ = decltype((std::declval<_Reschedule::Composable>() - | std::declval() - | std::declval<_Reschedule::Composable>()) + >> std::declval() + >> std::declval<_Reschedule::Composable>()) .template k(std::declval())); std::optional adapted_; diff --git a/eventuals/signal.h b/eventuals/signal.h index 697fda51..935acff7 100644 --- a/eventuals/signal.h +++ b/eventuals/signal.h @@ -38,13 +38,13 @@ namespace eventuals { template [[nodiscard]] auto WaitForOneOfSignals(int(&&signums)[N]) { return Iterate(std::move(signums)) - | Concurrent([]() { + >> Concurrent([]() { return Map([](int signum) { return WaitForSignal(signum) - | Just(signum); + >> Just(signum); }); }) - | Head(); + >> Head(); } //////////////////////////////////////////////////////////////////////// diff --git a/eventuals/task.h b/eventuals/task.h index 94698128..e26cc870 100644 --- a/eventuals/task.h +++ b/eventuals/task.h @@ -556,11 +556,11 @@ class _Task final { k_.emplace(Build( Reschedule(context_->Borrow()) - | std::move(e_) - | Terminal() - .start(std::move(start)) - .fail(std::move(fail)) - .stop(std::move(stop)))); + >> std::move(e_) + >> Terminal() + .start(std::move(start)) + .fail(std::move(fail)) + .stop(std::move(stop)))); k_->Register(interrupt_); @@ -642,11 +642,11 @@ class _Task final { k_.emplace(Build( Reschedule(context_->Borrow()) - | std::move(e_) - | Terminal() - .start(std::move(start)) - .fail(std::move(fail)) - .stop(std::move(stop)))); + >> std::move(e_) + >> Terminal() + .start(std::move(start)) + .fail(std::move(fail)) + .stop(std::move(stop)))); k_->Register(interrupt_); @@ -675,11 +675,11 @@ class _Task final { k_.emplace(Build( Reschedule(context_->Borrow()) - | std::move(e_) - | Terminal() - .start(std::move(start)) - .fail(std::move(fail)) - .stop(std::move(stop)))); + >> std::move(e_) + >> Terminal() + .start(std::move(start)) + .fail(std::move(fail)) + .stop(std::move(stop)))); k_->Register(interrupt_); @@ -803,11 +803,11 @@ class _Task final { Undefined, decltype(Build( Reschedule(context_->Borrow()) - | std::move(e_) - | Terminal() - .start(std::declval>&&>()) - .fail(std::declval&&>()) - .stop(std::declval&&>())))>; + >> std::move(e_) + >> Terminal() + .start(std::declval>&&>()) + .fail(std::declval&&>()) + .stop(std::declval&&>())))>; // NOTE: we store 'k_' as the _last_ member so it will be // destructed _first_ and thus we won't have any use-after-delete diff --git a/protoc-gen-eventuals/templates/eventuals.cc.j2 b/protoc-gen-eventuals/templates/eventuals.cc.j2 index 7195bccd..5e5dc370 100644 --- a/protoc-gen-eventuals/templates/eventuals.cc.j2 +++ b/protoc-gen-eventuals/templates/eventuals.cc.j2 @@ -48,12 +48,12 @@ Task::Of {{ service.name }}::TypeErasedService::Serve{{ method.name }}() { {{ namespaces | join('::') }}::{{ service.name }}, {{ input_type }}, {{ output_type }}>("{{ method.name }}") - | Concurrent([this]() { + >> Concurrent([this]() { return Map(Let([this](auto& call) { {%- if not method.server_streaming and not method.client_streaming %} {#- No streaming #} return UnaryPrologue(call) - | Then(Let([&](auto& request) { + >> Then(Let([&](auto& request) { return Then( [&, // NOTE: using a tuple because need @@ -66,7 +66,7 @@ Task::Of {{ service.name }}::TypeErasedService::Serve{{ method.name }}() { call.context(), &request}]() mutable { return TypeErased{{ method.name }}(&args) - | UnaryEpilogue(call); + >> UnaryEpilogue(call); }); })); {%- elif not method.server_streaming and method.client_streaming %} @@ -83,12 +83,12 @@ Task::Of {{ service.name }}::TypeErasedService::Serve{{ method.name }}() { call.context(), &call.Reader()}]() mutable { return TypeErased{{ method.name }}(&args) - | UnaryEpilogue(call); + >> UnaryEpilogue(call); }); {%- elif method.server_streaming and not method.client_streaming %} {#- Server streaming #} return UnaryPrologue(call) - | Then(Let([&](auto& request) { + >> Then(Let([&](auto& request) { return Then( [&, // NOTE: using a tuple because need @@ -101,7 +101,7 @@ Task::Of {{ service.name }}::TypeErasedService::Serve{{ method.name }}() { call.context(), &request}]() mutable { return TypeErased{{ method.name }}(&args) - | StreamingEpilogue(call); + >> StreamingEpilogue(call); }); })); {%- elif method.server_streaming and method.client_streaming %} @@ -118,12 +118,12 @@ Task::Of {{ service.name }}::TypeErasedService::Serve{{ method.name }}() { call.context(), &call.Reader()}]() mutable { return TypeErased{{ method.name }}(&args) - | StreamingEpilogue(call); + >> StreamingEpilogue(call); }); {%- endif %} }));{# Map #} }){# Concurrent #} - | Loop(); + >> Loop(); }; } {% endfor %} @@ -134,7 +134,7 @@ Task::Of {{ service.name }}::TypeErasedService::Serve() { {%- for method in service.methods %} Serve{{ method.name }}(){%- if not loop.last -%},{%- endif %} {% endfor %} - ) | Just(); // Return 'void'. + ) >> Just(); // Return 'void'. }; } {% endfor %} diff --git a/test/catch.cc b/test/catch.cc index 6853a7c5..0f5afff9 100644 --- a/test/catch.cc +++ b/test/catch.cc @@ -21,18 +21,18 @@ using testing::MockFunction; TEST(CatchTest, RaisedRuntimeError) { auto e = []() { return Just(1) - | Raise(std::runtime_error("message")) - | Catch() - .raised([](auto&& error) { - ADD_FAILURE() << "Encountered unexpected matched raised"; - return Then([]() { - return 100; - }); - }) - .raised([](auto&& error) { - EXPECT_STREQ(error.what(), "message"); - return Just(100); - }); + >> Raise(std::runtime_error("message")) + >> Catch() + .raised([](auto&& error) { + ADD_FAILURE() << "Encountered unexpected matched raised"; + return Then([]() { + return 100; + }); + }) + .raised([](auto&& error) { + EXPECT_STREQ(error.what(), "message"); + return Just(100); + }); }; static_assert( @@ -52,17 +52,17 @@ TEST(CatchTest, ChildException) { auto e = []() { return Just(1) - | Raise(Error{}) - | Catch() - .raised([](auto&& error) { - ADD_FAILURE() << "Encountered unexpected matched raised"; - return Just(10); - }) - .raised( - [](auto&& error) { - EXPECT_STREQ("child exception", error.what()); - return Just(100); - }); + >> Raise(Error{}) + >> Catch() + .raised([](auto&& error) { + ADD_FAILURE() << "Encountered unexpected matched raised"; + return Just(10); + }) + .raised( + [](auto&& error) { + EXPECT_STREQ("child exception", error.what()); + return Just(100); + }); }; static_assert( @@ -76,25 +76,25 @@ TEST(CatchTest, ChildException) { TEST(CatchTest, All) { auto e = []() { return Just(500) - | Raise(std::runtime_error("10")) - | Catch() - .raised([](auto&& error) { - ADD_FAILURE() << "Encountered unexpected matched raised"; - return 10; - }) - .raised([](auto&& error) { - ADD_FAILURE() << "Encountered unexpected matched raised"; - return 10; - }) - .all([](std::exception_ptr&& error) { - try { - std::rethrow_exception(error); - } catch (const std::runtime_error& error) { - EXPECT_STREQ(error.what(), "10"); - } - return 100; - }) - | Then([](int&& value) { + >> Raise(std::runtime_error("10")) + >> Catch() + .raised([](auto&& error) { + ADD_FAILURE() << "Encountered unexpected matched raised"; + return 10; + }) + .raised([](auto&& error) { + ADD_FAILURE() << "Encountered unexpected matched raised"; + return 10; + }) + .all([](std::exception_ptr&& error) { + try { + std::rethrow_exception(error); + } catch (const std::runtime_error& error) { + EXPECT_STREQ(error.what(), "10"); + } + return 100; + }) + >> Then([](int&& value) { return value; }); }; @@ -120,17 +120,17 @@ TEST(CatchTest, UnexpectedRaise) { auto e = [&]() { return f() // Throwing 'std::exception_ptr' there. - | Catch() - .raised([](auto&& error) { - ADD_FAILURE() << "Encountered unexpected matched raised"; - return 1; - }) - // Receive 'Error' type there, that had been rethrowed from - // 'std::exception_ptr'. - .raised([](auto&& error) { - EXPECT_STREQ("child exception", error.what()); - return 100; - }); + >> Catch() + .raised([](auto&& error) { + ADD_FAILURE() << "Encountered unexpected matched raised"; + return 1; + }) + // Receive 'Error' type there, that had been rethrowed from + // 'std::exception_ptr'. + .raised([](auto&& error) { + EXPECT_STREQ("child exception", error.what()); + return 100; + }); }; static_assert( @@ -154,26 +154,26 @@ TEST(CatchTest, UnexpectedAll) { auto e = [&]() { return f() // Throwing 'std::exception_ptr' there. - | Catch() - .raised([](auto&& error) { - ADD_FAILURE() << "Encountered unexpected matched raised"; - return 1; - }) - .raised([](auto&& error) { - ADD_FAILURE() << "Encountered unexpected matched raised"; - return 1; - }) - .all([](std::exception_ptr&& error) { - try { - std::rethrow_exception(error); - } catch (const Error& e) { - EXPECT_STREQ(e.what(), "child exception"); - } catch (...) { - ADD_FAILURE() << "Failure on rethrowing"; - } - - return 100; - }); + >> Catch() + .raised([](auto&& error) { + ADD_FAILURE() << "Encountered unexpected matched raised"; + return 1; + }) + .raised([](auto&& error) { + ADD_FAILURE() << "Encountered unexpected matched raised"; + return 1; + }) + .all([](std::exception_ptr&& error) { + try { + std::rethrow_exception(error); + } catch (const Error& e) { + EXPECT_STREQ(e.what(), "child exception"); + } catch (...) { + ADD_FAILURE() << "Failure on rethrowing"; + } + + return 100; + }); }; static_assert( @@ -187,16 +187,16 @@ TEST(CatchTest, UnexpectedAll) { TEST(CatchTest, NoExactHandler) { auto e = []() { return Just(1) - | Raise(std::string("error")) - | Catch() - .raised([](auto&& error) { - ADD_FAILURE() << "Encountered unexpected matched raised"; - return 1; - }) - .raised([](auto&& error) { - ADD_FAILURE() << "Encountered unexpected matched raised"; - return 1; - }); + >> Raise(std::string("error")) + >> Catch() + .raised([](auto&& error) { + ADD_FAILURE() << "Encountered unexpected matched raised"; + return 1; + }) + .raised([](auto&& error) { + ADD_FAILURE() << "Encountered unexpected matched raised"; + return 1; + }); }; static_assert( @@ -210,25 +210,25 @@ TEST(CatchTest, NoExactHandler) { TEST(CatchTest, ReRaise) { auto e = []() { return Just(1) - | Raise("10") - | Catch() - .raised([](auto&& error) { - EXPECT_STREQ(error.what(), "10"); - return Raise("1"); - }) - .all([](std::exception_ptr&& error) { - ADD_FAILURE() << "Encountered an unexpected all"; - return Just(100); - }) - | Then([](auto&&) { + >> Raise("10") + >> Catch() + .raised([](auto&& error) { + EXPECT_STREQ(error.what(), "10"); + return Raise("1"); + }) + .all([](std::exception_ptr&& error) { + ADD_FAILURE() << "Encountered an unexpected all"; + return Just(100); + }) + >> Then([](auto&&) { return 200; }) - | Catch() - .raised([](auto&& error) { - EXPECT_STREQ(error.what(), "1"); - return Just(10); - }) - | Then([](auto value) { + >> Catch() + .raised([](auto&& error) { + EXPECT_STREQ(error.what(), "1"); + return Just(10); + }) + >> Then([](auto value) { return value; }); }; @@ -244,15 +244,15 @@ TEST(CatchTest, ReRaise) { TEST(CatchTest, VoidPropagate) { auto e = []() { return Just("error") - | Then([](const char* i) { + >> Then([](const char* i) { return; }) - | Catch() - .raised([](auto&& error) { - EXPECT_STREQ(error.what(), "error"); - // MUST RETURN VOID HERE! - }) - | Then([](/* MUST TAKE VOID HERE! */) { + >> Catch() + .raised([](auto&& error) { + EXPECT_STREQ(error.what(), "error"); + // MUST RETURN VOID HERE! + }) + >> Then([](/* MUST TAKE VOID HERE! */) { return 100; }); }; @@ -268,19 +268,19 @@ TEST(CatchTest, VoidPropagate) { TEST(CatchTest, Interrupt) { auto e = []() { return Just(1) - | Raise(std::runtime_error("message")) - | Catch() - .raised([](auto&& error) { - ADD_FAILURE() << "Encountered unexpected matched raised"; - return Then([]() { - return 100; - }); - }) - .raised([](auto&& error) { - EXPECT_STREQ(error.what(), "message"); - return Just(100); - }) - | Then([](int i) { + >> Raise(std::runtime_error("message")) + >> Catch() + .raised([](auto&& error) { + ADD_FAILURE() << "Encountered unexpected matched raised"; + return Then([]() { + return 100; + }); + }) + .raised([](auto&& error) { + EXPECT_STREQ(error.what(), "message"); + return Just(100); + }) + >> Then([](int i) { return std::to_string(i); }); }; diff --git a/test/closure.cc b/test/closure.cc index 0683e502..0cebc790 100644 --- a/test/closure.cc +++ b/test/closure.cc @@ -29,7 +29,7 @@ using testing::ThrowsMessage; TEST(ClosureTest, Then) { auto e = []() { return Just(1) - | Closure([i = 41]() { + >> Closure([i = 41]() { return Then([&](auto&& value) { return i + value; }); }); }; @@ -49,7 +49,7 @@ TEST(ClosureTest, Functor) { auto e = []() { return Just(1) - | Closure(Functor{41}); + >> Closure(Functor{41}); }; EXPECT_EQ(42, *e()); @@ -59,7 +59,7 @@ TEST(ClosureTest, Functor) { TEST(ClosureTest, OuterRepeat) { auto e = []() { return Repeat([]() { return 1; }) - | Closure([i = 41]() { + >> Closure([i = 41]() { return Reduce( i, [](auto& i) { @@ -79,15 +79,15 @@ TEST(ClosureTest, InnerRepeat) { auto e = []() { return Closure([strings = deque{"hello", "world"}]() mutable { return Repeat() - | Until([&]() { + >> Until([&]() { return strings.empty(); }) - | Map([&]() mutable { + >> Map([&]() mutable { auto s = std::move(strings.front()); strings.pop_front(); return s; }) - | Reduce( + >> Reduce( deque(), [](auto& results) { return Then([&](auto&& result) mutable { @@ -107,7 +107,7 @@ TEST(ClosureTest, InnerRepeat) { TEST(ClosureTest, Fail) { auto e = []() { return Raise("error") - | Closure([i = 41]() { + >> Closure([i = 41]() { return Then([&]() { return i + 1; }); }); }; @@ -129,7 +129,7 @@ TEST(ClosureTest, Interrupt) { auto e = [&]() { return Just(1) - | Closure([&]() { + >> Closure([&]() { return Eventual() .interruptible() .start([&](auto& k, auto& handler, auto&&) { diff --git a/test/collect.cc b/test/collect.cc index 86b56c74..7a1ac5a6 100644 --- a/test/collect.cc +++ b/test/collect.cc @@ -19,7 +19,7 @@ TEST(Collect, VectorPass) { auto s = [&]() { return Iterate(v) - | Collect(); + >> Collect(); }; std::vector result = *s(); @@ -38,7 +38,7 @@ TEST(Collect, SetPass) { auto s = [&]() { return Iterate(v) - | Collect(); + >> Collect(); }; std::set result = *s(); @@ -57,7 +57,7 @@ TEST(Collect, TypedCollection) { auto s = [&]() { return Iterate(v) - | Collect>(); + >> Collect>(); }; std::vector result = *s(); diff --git a/test/concurrent/downstream-done-both-eventuals-success.cc b/test/concurrent/downstream-done-both-eventuals-success.cc index 81f27ad3..f1213386 100644 --- a/test/concurrent/downstream-done-both-eventuals-success.cc +++ b/test/concurrent/downstream-done-both-eventuals-success.cc @@ -22,7 +22,7 @@ TYPED_TEST(ConcurrentTypedTest, DownstreamDoneBothEventualsSuccess) { auto e = [&]() { return Iterate({1, 2}) - | this->ConcurrentOrConcurrentOrdered([&]() { + >> this->ConcurrentOrConcurrentOrdered([&]() { return Map(Let([&](int& i) { return Eventual() .start([&](auto& k) mutable { @@ -38,7 +38,7 @@ TYPED_TEST(ConcurrentTypedTest, DownstreamDoneBothEventualsSuccess) { }); })); }) - | Reduce( + >> Reduce( std::string(), [](auto& result) { return Then([&](auto&& value) { diff --git a/test/concurrent/downstream-done-one-eventual-fail.cc b/test/concurrent/downstream-done-one-eventual-fail.cc index 1fbf0f41..57fd0946 100644 --- a/test/concurrent/downstream-done-one-eventual-fail.cc +++ b/test/concurrent/downstream-done-one-eventual-fail.cc @@ -22,7 +22,7 @@ TYPED_TEST(ConcurrentTypedTest, DownstreamDoneOneEventualFail) { auto e = [&]() { return Iterate({1, 2}) - | this->ConcurrentOrConcurrentOrdered([&]() { + >> this->ConcurrentOrConcurrentOrdered([&]() { return Map(Let([&](int& i) { return Eventual() .raises() @@ -42,7 +42,7 @@ TYPED_TEST(ConcurrentTypedTest, DownstreamDoneOneEventualFail) { }); })); }) - | Reduce( + >> Reduce( std::string(), [](auto& result) { return Then([&](auto&& value) { diff --git a/test/concurrent/downstream-done-one-eventual-stop.cc b/test/concurrent/downstream-done-one-eventual-stop.cc index c11e4722..d1ad898a 100644 --- a/test/concurrent/downstream-done-one-eventual-stop.cc +++ b/test/concurrent/downstream-done-one-eventual-stop.cc @@ -22,7 +22,7 @@ TYPED_TEST(ConcurrentTypedTest, DownstreamDoneOneEventualStop) { auto e = [&]() { return Iterate({1, 2}) - | this->ConcurrentOrConcurrentOrdered([&]() { + >> this->ConcurrentOrConcurrentOrdered([&]() { return Map(Let([&](int& i) { return Eventual() .interruptible() @@ -41,7 +41,7 @@ TYPED_TEST(ConcurrentTypedTest, DownstreamDoneOneEventualStop) { }); })); }) - | Reduce( + >> Reduce( std::string(), [](auto& result) { return Then([&](auto&& value) { diff --git a/test/concurrent/emit-fail-interrupt.cc b/test/concurrent/emit-fail-interrupt.cc index 6c0a21a5..b12e1098 100644 --- a/test/concurrent/emit-fail-interrupt.cc +++ b/test/concurrent/emit-fail-interrupt.cc @@ -43,7 +43,7 @@ TYPED_TEST(ConcurrentTypedTest, EmitFailInterrupt) { k.Emit(i); } }) - | this->ConcurrentOrConcurrentOrdered([&]() { + >> this->ConcurrentOrConcurrentOrdered([&]() { return Map(Let([&](int& i) { return Eventual() .raises() @@ -53,7 +53,7 @@ TYPED_TEST(ConcurrentTypedTest, EmitFailInterrupt) { }); })); }) - | Collect(); + >> Collect(); }; static_assert( diff --git a/test/concurrent/emit-interrupt-fail.cc b/test/concurrent/emit-interrupt-fail.cc index 6e663c2e..f3b65d15 100644 --- a/test/concurrent/emit-interrupt-fail.cc +++ b/test/concurrent/emit-interrupt-fail.cc @@ -34,12 +34,12 @@ TYPED_TEST(ConcurrentTypedTest, EmitInterruptFail) { k.Emit(i); } }) - | this->ConcurrentOrConcurrentOrdered([]() { + >> this->ConcurrentOrConcurrentOrdered([]() { return Map([](int i) { return std::to_string(i); }); }) - | Collect(); + >> Collect(); }; static_assert( diff --git a/test/concurrent/emit-interrupt-stop.cc b/test/concurrent/emit-interrupt-stop.cc index 92309048..8a2dcc40 100644 --- a/test/concurrent/emit-interrupt-stop.cc +++ b/test/concurrent/emit-interrupt-stop.cc @@ -30,12 +30,12 @@ TYPED_TEST(ConcurrentTypedTest, EmitInterruptStop) { k.Emit(i); } }) - | this->ConcurrentOrConcurrentOrdered([]() { + >> this->ConcurrentOrConcurrentOrdered([]() { return Map([](int i) { return std::to_string(i); }); }) - | Collect(); + >> Collect(); }; static_assert( diff --git a/test/concurrent/emit-stop-interrupt.cc b/test/concurrent/emit-stop-interrupt.cc index 48779d38..38ee3713 100644 --- a/test/concurrent/emit-stop-interrupt.cc +++ b/test/concurrent/emit-stop-interrupt.cc @@ -33,7 +33,7 @@ TYPED_TEST(ConcurrentTypedTest, EmitStopInterrupt) { k.Emit(i); } }) - | this->ConcurrentOrConcurrentOrdered([&]() { + >> this->ConcurrentOrConcurrentOrdered([&]() { return Map(Let([&](int& i) { return Eventual([&](auto& k) { k.Stop(); @@ -41,7 +41,7 @@ TYPED_TEST(ConcurrentTypedTest, EmitStopInterrupt) { }); })); }) - | Collect(); + >> Collect(); }; static_assert( diff --git a/test/concurrent/fail-before-start.cc b/test/concurrent/fail-before-start.cc index 729a863b..1b715dc7 100644 --- a/test/concurrent/fail-before-start.cc +++ b/test/concurrent/fail-before-start.cc @@ -24,7 +24,7 @@ TYPED_TEST(ConcurrentTypedTest, FailBeforeStart) { auto e = [&]() { return Iterate({1, 2}) - | this->ConcurrentOrConcurrentOrdered([&]() { + >> this->ConcurrentOrConcurrentOrdered([&]() { struct Data { void* k; int i; @@ -49,7 +49,7 @@ TYPED_TEST(ConcurrentTypedTest, FailBeforeStart) { }); })); }) - | Collect(); + >> Collect(); }; static_assert( diff --git a/test/concurrent/fail-or-stop.cc b/test/concurrent/fail-or-stop.cc index 3399dfa8..caf5bc9c 100644 --- a/test/concurrent/fail-or-stop.cc +++ b/test/concurrent/fail-or-stop.cc @@ -20,7 +20,7 @@ TYPED_TEST(ConcurrentTypedTest, FailOrStop) { auto e = [&]() { return Iterate({1, 2}) - | this->ConcurrentOrConcurrentOrdered([&]() { + >> this->ConcurrentOrConcurrentOrdered([&]() { struct Data { void* k; int i; @@ -43,7 +43,7 @@ TYPED_TEST(ConcurrentTypedTest, FailOrStop) { }); })); }) - | Collect(); + >> Collect(); }; static_assert( diff --git a/test/concurrent/fail.cc b/test/concurrent/fail.cc index 8e7cb591..5c1e741d 100644 --- a/test/concurrent/fail.cc +++ b/test/concurrent/fail.cc @@ -24,7 +24,7 @@ TYPED_TEST(ConcurrentTypedTest, Fail) { auto e = [&]() { return Iterate({1, 2}) - | this->ConcurrentOrConcurrentOrdered([&]() { + >> this->ConcurrentOrConcurrentOrdered([&]() { struct Data { void* k; int i; @@ -47,7 +47,7 @@ TYPED_TEST(ConcurrentTypedTest, Fail) { }); })); }) - | Collect(); + >> Collect(); }; static_assert( diff --git a/test/concurrent/flat-map.cc b/test/concurrent/flat-map.cc index 3f5c93c0..5f75e1f4 100644 --- a/test/concurrent/flat-map.cc +++ b/test/concurrent/flat-map.cc @@ -19,12 +19,12 @@ namespace { TYPED_TEST(ConcurrentTypedTest, FlatMap) { auto e = [&]() { return Iterate({1, 2}) - | this->ConcurrentOrConcurrentOrdered([]() { + >> this->ConcurrentOrConcurrentOrdered([]() { return FlatMap([](int i) { return Range(i); }); }) - | Collect(); + >> Collect(); }; static_assert( diff --git a/test/concurrent/interrupt-fail-or-stop.cc b/test/concurrent/interrupt-fail-or-stop.cc index deb271d0..3418548a 100644 --- a/test/concurrent/interrupt-fail-or-stop.cc +++ b/test/concurrent/interrupt-fail-or-stop.cc @@ -28,7 +28,7 @@ TYPED_TEST(ConcurrentTypedTest, InterruptFailOrStop) { auto e = [&]() { return Iterate({1, 2}) - | this->ConcurrentOrConcurrentOrdered([&]() { + >> this->ConcurrentOrConcurrentOrdered([&]() { return Map(Let([&](int& i) { return Eventual() .raises() @@ -48,7 +48,7 @@ TYPED_TEST(ConcurrentTypedTest, InterruptFailOrStop) { }); })); }) - | Collect(); + >> Collect(); }; static_assert( diff --git a/test/concurrent/interrupt-fail.cc b/test/concurrent/interrupt-fail.cc index 8ef1a1d7..53251bf1 100644 --- a/test/concurrent/interrupt-fail.cc +++ b/test/concurrent/interrupt-fail.cc @@ -27,7 +27,7 @@ TYPED_TEST(ConcurrentTypedTest, InterruptFail) { auto e = [&]() { return Iterate({1, 2}) - | this->ConcurrentOrConcurrentOrdered([&]() { + >> this->ConcurrentOrConcurrentOrdered([&]() { return Map(Let([&](int& i) { return Eventual() .raises() @@ -41,7 +41,7 @@ TYPED_TEST(ConcurrentTypedTest, InterruptFail) { }); })); }) - | Collect(); + >> Collect(); }; static_assert( diff --git a/test/concurrent/interrupt-stop.cc b/test/concurrent/interrupt-stop.cc index 0ff1857c..8b21ca43 100644 --- a/test/concurrent/interrupt-stop.cc +++ b/test/concurrent/interrupt-stop.cc @@ -23,7 +23,7 @@ TYPED_TEST(ConcurrentTypedTest, InterruptStop) { auto e = [&]() { return Iterate({1, 2}) - | this->ConcurrentOrConcurrentOrdered([&]() { + >> this->ConcurrentOrConcurrentOrdered([&]() { return Map(Let([&](int& i) { return Eventual() .interruptible() @@ -36,7 +36,7 @@ TYPED_TEST(ConcurrentTypedTest, InterruptStop) { }); })); }) - | Collect(); + >> Collect(); }; static_assert( diff --git a/test/concurrent/interrupt-success.cc b/test/concurrent/interrupt-success.cc index e7dea352..13359664 100644 --- a/test/concurrent/interrupt-success.cc +++ b/test/concurrent/interrupt-success.cc @@ -23,7 +23,7 @@ TYPED_TEST(ConcurrentTypedTest, InterruptSuccess) { auto e = [&]() { return Iterate({1, 2}) - | this->ConcurrentOrConcurrentOrdered([&]() { + >> this->ConcurrentOrConcurrentOrdered([&]() { struct Data { void* k; int i; @@ -40,7 +40,7 @@ TYPED_TEST(ConcurrentTypedTest, InterruptSuccess) { }); })); }) - | Collect(); + >> Collect(); }; static_assert( diff --git a/test/concurrent/moveable.cc b/test/concurrent/moveable.cc index aa0b441e..3784b115 100644 --- a/test/concurrent/moveable.cc +++ b/test/concurrent/moveable.cc @@ -21,12 +21,12 @@ TYPED_TEST(ConcurrentTypedTest, Moveable) { auto e = [&]() { return Iterate({Moveable()}) - | this->ConcurrentOrConcurrentOrdered([]() { + >> this->ConcurrentOrConcurrentOrdered([]() { return Map(Let([](auto& moveable) { return 42; })); }) - | Collect(); + >> Collect(); }; static_assert( diff --git a/test/concurrent/stop-before-start.cc b/test/concurrent/stop-before-start.cc index e8050ba4..fd2a4c96 100644 --- a/test/concurrent/stop-before-start.cc +++ b/test/concurrent/stop-before-start.cc @@ -20,7 +20,7 @@ TYPED_TEST(ConcurrentTypedTest, StopBeforeStart) { auto e = [&]() { return Iterate({1, 2}) - | this->ConcurrentOrConcurrentOrdered([&]() { + >> this->ConcurrentOrConcurrentOrdered([&]() { struct Data { void* k; int i; @@ -43,7 +43,7 @@ TYPED_TEST(ConcurrentTypedTest, StopBeforeStart) { }); })); }) - | Collect(); + >> Collect(); }; static_assert( diff --git a/test/concurrent/stop.cc b/test/concurrent/stop.cc index 25f800da..0cb3b363 100644 --- a/test/concurrent/stop.cc +++ b/test/concurrent/stop.cc @@ -20,7 +20,7 @@ TYPED_TEST(ConcurrentTypedTest, Stop) { auto e = [&]() { return Iterate({1, 2}) - | this->ConcurrentOrConcurrentOrdered([&]() { + >> this->ConcurrentOrConcurrentOrdered([&]() { struct Data { void* k; int i; @@ -41,7 +41,7 @@ TYPED_TEST(ConcurrentTypedTest, Stop) { }); })); }) - | Collect(); + >> Collect(); }; static_assert( diff --git a/test/concurrent/stream-fail.cc b/test/concurrent/stream-fail.cc index 6249d0b5..a6a9bb0a 100644 --- a/test/concurrent/stream-fail.cc +++ b/test/concurrent/stream-fail.cc @@ -22,12 +22,12 @@ TYPED_TEST(ConcurrentTypedTest, StreamFail) { .next([](auto& k) { k.Fail(std::runtime_error("error")); }) - | this->ConcurrentOrConcurrentOrdered([]() { + >> this->ConcurrentOrConcurrentOrdered([]() { return Map([](int i) { return std::to_string(i); }); }) - | Collect(); + >> Collect(); }; static_assert( diff --git a/test/concurrent/stream-stop.cc b/test/concurrent/stream-stop.cc index 8d238174..9ae84fcc 100644 --- a/test/concurrent/stream-stop.cc +++ b/test/concurrent/stream-stop.cc @@ -17,12 +17,12 @@ TYPED_TEST(ConcurrentTypedTest, StreamStop) { .next([](auto& k) { k.Stop(); }) - | this->ConcurrentOrConcurrentOrdered([]() { + >> this->ConcurrentOrConcurrentOrdered([]() { return Map([](int i) { return std::to_string(i); }); }) - | Collect(); + >> Collect(); }; static_assert( diff --git a/test/concurrent/success.cc b/test/concurrent/success.cc index eaf35670..180c74ab 100644 --- a/test/concurrent/success.cc +++ b/test/concurrent/success.cc @@ -20,7 +20,7 @@ TYPED_TEST(ConcurrentTypedTest, Success) { auto e = [&]() { return Iterate({1, 2}) - | this->ConcurrentOrConcurrentOrdered([&]() { + >> this->ConcurrentOrConcurrentOrdered([&]() { struct Data { void* k; int i; @@ -37,7 +37,7 @@ TYPED_TEST(ConcurrentTypedTest, Success) { }); })); }) - | Collect(); + >> Collect(); }; static_assert( diff --git a/test/conditional.cc b/test/conditional.cc index fd56e9a9..31f9df0e 100644 --- a/test/conditional.cc +++ b/test/conditional.cc @@ -35,8 +35,8 @@ TEST(ConditionalTest, Then) { auto c = [&]() { return Just(1) - | Then([](int i) { return i + 1; }) - | Conditional( + >> Then([](int i) { return i + 1; }) + >> Conditional( [](auto&& i) { return i > 1; }, [&](auto&&) { return then(); }, [&](auto&&) { return els3(); }); @@ -63,8 +63,8 @@ TEST(ConditionalTest, Else) { auto c = [&]() { return Just(0) - | Then([](int i) { return i + 1; }) - | Conditional( + >> Then([](int i) { return i + 1; }) + >> Conditional( [](auto&& i) { return i > 1; }, [&](auto&&) { return then(); }, [&](auto&&) { return els3(); }); @@ -99,8 +99,8 @@ TEST(ConditionalTest, Fail) { }); thread.detach(); }) - | Then([](int i) { return i + 1; }) - | Conditional( + >> Then([](int i) { return i + 1; }) + >> Conditional( [](auto&& i) { return i > 1; }, [&](auto&&) { return then(); }, [&](auto&&) { return els3(); }); @@ -142,8 +142,8 @@ TEST(ConditionalTest, Interrupt) { auto c = [&]() { return Just(1) - | Then([](int i) { return i + 1; }) - | Conditional( + >> Then([](int i) { return i + 1; }) + >> Conditional( [](auto&& i) { return i > 1; }, [&](auto&&) { return then(); }, [&](auto&&) { return els3(); }); @@ -169,8 +169,8 @@ TEST(ConditionalTest, Interrupt) { TEST(ConditionalTest, Raise) { auto c = [&]() { return Just(1) - | Then([](int i) { return i + 1; }) - | Conditional( + >> Then([](int i) { return i + 1; }) + >> Conditional( [](auto&& i) { return i > 1; }, [](auto&& i) { return Just(i); }, [](auto&& i) { return Raise("raise"); }); diff --git a/test/dns-resolver.cc b/test/dns-resolver.cc index c6d65900..b039727d 100644 --- a/test/dns-resolver.cc +++ b/test/dns-resolver.cc @@ -55,18 +55,18 @@ TEST_F(DomainNameResolveTest, Fail) { TEST_F(DomainNameResolveTest, Stop) { std::string address = "localhost", port = "6667"; auto e = DomainNameResolve(address, port) - | Eventual() - .start([](auto& k, auto&& ip) { - // Imagine that we got ip, and we try to connect - // in order to get some data (int) from db for example, - // but there was an error and we stop our continuation. - bool error = true; - if (error) { - k.Stop(); - } else - k.Start(13); - }) - | Then([](int data) { + >> Eventual() + .start([](auto& k, auto&& ip) { + // Imagine that we got ip, and we try to connect + // in order to get some data (int) from db for example, + // but there was an error and we stop our continuation. + bool error = true; + if (error) { + k.Stop(); + } else + k.Start(13); + }) + >> Then([](int data) { return std::to_string(data); }); @@ -76,19 +76,19 @@ TEST_F(DomainNameResolveTest, Stop) { TEST_F(DomainNameResolveTest, Raises) { std::string address = "localhost", port = "6667"; auto e = DomainNameResolve(address, port) - | Eventual() - .raises() - .start([](auto& k, auto&& ip) { - // Imagine that we got ip, and we try to connect - // in order to get some data (int) from db for example, - // but there was an error and we stop our continuation. - bool error = true; - if (error) { - k.Fail(std::overflow_error("error")); - } else - k.Start(13); - }) - | Then([](int data) { + >> Eventual() + .raises() + .start([](auto& k, auto&& ip) { + // Imagine that we got ip, and we try to connect + // in order to get some data (int) from db for example, + // but there was an error and we stop our continuation. + bool error = true; + if (error) { + k.Fail(std::overflow_error("error")); + } else + k.Start(13); + }) + >> Then([](int data) { return std::to_string(data); }); diff --git a/test/eventual.cc b/test/eventual.cc index c12968dc..a43b24b3 100644 --- a/test/eventual.cc +++ b/test/eventual.cc @@ -41,22 +41,22 @@ TEST(EventualTest, Succeed) { }); thread.detach(); }) - | Then([](int i) { return i + 2; }) - | Eventual() - .context(9) - .start([](auto& context, auto& k, auto&& value) { - auto thread = std::thread( - [value, &context, &k]() mutable { - k.Start(context - value); - }); - thread.detach(); - }) - .fail([&](auto&, auto&, auto&&) { - fail.Call(); - }) - .stop([&](auto&, auto&) { - stop.Call(); - }); + >> Then([](int i) { return i + 2; }) + >> Eventual() + .context(9) + .start([](auto& context, auto& k, auto&& value) { + auto thread = std::thread( + [value, &context, &k]() mutable { + k.Start(context - value); + }); + thread.detach(); + }) + .fail([&](auto&, auto&, auto&&) { + fail.Call(); + }) + .stop([&](auto&, auto&) { + stop.Call(); + }); }; EXPECT_EQ(2, *e()); @@ -84,14 +84,14 @@ TEST(EventualTest, Fail) { }); thread.detach(); }) - | Then([](int i) { return i + 2; }) - | Eventual() - .start([&](auto& k, auto&& value) { - start.Call(); - }) - .stop([&](auto&) { - stop.Call(); - }); + >> Then([](int i) { return i + 2; }) + >> Eventual() + .start([&](auto& k, auto&& value) { + start.Call(); + }) + .stop([&](auto&) { + stop.Call(); + }); }; EXPECT_THAT( @@ -119,17 +119,17 @@ TEST(EventualTest, Interrupt) { }); start.Call(); }) - | Then([](int i) { return i + 2; }) - | Eventual() - .start([&](auto&, auto&&) { - start.Call(); - }) - .fail([&](auto&, auto&&) { - fail.Call(); - }) - .stop([](auto& k) { - k.Stop(); - }); + >> Then([](int i) { return i + 2; }) + >> Eventual() + .start([&](auto&, auto&&) { + start.Call(); + }) + .fail([&](auto&, auto&&) { + fail.Call(); + }) + .stop([](auto& k) { + k.Stop(); + }); }; auto [future, k] = PromisifyForTest(e()); @@ -160,31 +160,31 @@ TEST(EventualTest, Reuse) { }); thread.detach(); })) - | Then([](int i) { return i + 2; }) - | Eventual() - .context(9) - .start([](auto& context, auto& k, auto&& value) { - auto thread = std::thread( - [value, &context, &k]() mutable { - k.Start(context - value); - }); - thread.detach(); - }) - | Terminal() - .context(std::move(promise)) - .start([](auto& promise, auto&& value) { - promise.set_value(std::forward(value)); - }) - .fail([](auto& promise, auto&& error) { - promise.set_exception( - make_exception_ptr_or_forward( - std::forward(error))); - }) - .stop([](auto& promise) { - promise.set_exception( - std::make_exception_ptr( - eventuals::StoppedException())); - }); + >> Then([](int i) { return i + 2; }) + >> Eventual() + .context(9) + .start([](auto& context, auto& k, auto&& value) { + auto thread = std::thread( + [value, &context, &k]() mutable { + k.Start(context - value); + }); + thread.detach(); + }) + >> Terminal() + .context(std::move(promise)) + .start([](auto& promise, auto&& value) { + promise.set_value(std::forward(value)); + }) + .fail([](auto& promise, auto&& error) { + promise.set_exception( + make_exception_ptr_or_forward( + std::forward(error))); + }) + .stop([](auto& promise) { + promise.set_exception( + std::make_exception_ptr( + eventuals::StoppedException())); + }); }; using Operation = decltype(Build(operation(int(), std::promise()))); @@ -215,9 +215,9 @@ TEST(EventualTest, Reuse) { TEST(EventualTest, Raise) { auto e = []() { return Just(42) - | Raise("error") - | Raise("another error") - | Just(12); + >> Raise("error") + >> Raise("another error") + >> Just(12); }; static_assert( @@ -234,11 +234,11 @@ TEST(EventualTest, Raise) { TEST(EventualTest, Catch) { auto e = []() { return Just(41) - | Raise("error") - | Catch([](auto&&... error) { // The same as 'std::exception_ptr&&'. + >> Raise("error") + >> Catch([](auto&&... error) { // The same as 'std::exception_ptr&&'. return 42; }) - | Then([](int&& value) { + >> Then([](int&& value) { return value; }); }; @@ -255,8 +255,8 @@ TEST(EventualTest, Catch) { TEST(EventualTest, CatchVoid) { auto e = []() { return Just() - | Raise("error") - | Catch(Let([](auto& error) { + >> Raise("error") + >> Catch(Let([](auto& error) { return Then([&]() { try { std::rethrow_exception(error); @@ -265,7 +265,7 @@ TEST(EventualTest, CatchVoid) { } }); })) - | Then([]() { + >> Then([]() { return 42; }); }; @@ -277,10 +277,10 @@ TEST(EventualTest, CatchVoid) { TEST(EventualTest, Then) { auto e = []() { return Just(20) - | Then([](auto i) { + >> Then([](auto i) { return i + 1; }) - | Then([](auto j) { + >> Then([](auto j) { return j * 2; }); }; @@ -296,7 +296,7 @@ TEST(EventualTest, ConstRef) { return Eventual([&](auto& k) { k.Start(std::cref(x)); }) - | Then([](const int& x) { + >> Then([](const int& x) { return std::cref(x); }); }; @@ -318,7 +318,7 @@ TEST(EventualTest, Ref) { return Eventual([&](auto& k) { k.Start(std::ref(x)); }) - | Then([](int& x) { + >> Then([](int& x) { x += 100; }); }; diff --git a/test/executor.cc b/test/executor.cc index 86e53095..b718c0be 100644 --- a/test/executor.cc +++ b/test/executor.cc @@ -23,10 +23,10 @@ TEST(ExecutorTest, Succeed) { executed = true; return Just(); })) - | Then([&]() { + >> Then([&]() { return executor.Shutdown(); }) - | Then([&]() { + >> Then([&]() { return executor.Wait(); }); }; @@ -57,10 +57,10 @@ TEST(ExecutorTest, Interrupt) { }); }); })) - | Then([&]() { + >> Then([&]() { return executor.InterruptAndShutdown(); }) - | Then([&]() { + >> Then([&]() { return executor.Wait(); }); }; diff --git a/test/expected.cc b/test/expected.cc index 724b0da9..b20d7870 100644 --- a/test/expected.cc +++ b/test/expected.cc @@ -20,13 +20,13 @@ TEST(Expected, Compose) { auto e = [&]() { return f() - | Then([](int i) -> expected { + >> Then([](int i) -> expected { return tl::expected(i + 1); }) - | Then([](int i) { + >> Then([](int i) { return Just(expected(i)); }) - | Then([](expected e) { + >> Then([](expected e) { CHECK(e.has_value()); e = tl::expected(e.value() + 1); return e; @@ -43,7 +43,7 @@ TEST(Expected, NoRaisesDeclarationUnexpected) { auto e = [&]() { return f() - | Then([](int i) { + >> Then([](int i) { return i + 1; }); }; @@ -71,7 +71,7 @@ TEST(Expected, NoRaisesDeclarationUnexpectedFromDerivedException) { auto e = [&]() { return f() - | Then([](int i) { + >> Then([](int i) { return i + 1; }); }; @@ -99,7 +99,7 @@ TEST(Expected, RaisesDeclarationUnexpectedFromDerivedException) { auto e = [&]() { return f() - | Then([](int i) { + >> Then([](int i) { return i + 1; }); }; diff --git a/test/filesystem.cc b/test/filesystem.cc index f7b961aa..bcc07595 100644 --- a/test/filesystem.cc +++ b/test/filesystem.cc @@ -29,12 +29,12 @@ TEST_F(FilesystemTest, OpenAndCloseFileSucceed) { auto e = [&path]() { return OpenFile(path, UV_FS_O_RDONLY, 0) - | Then([&path](auto&& file) { + >> Then([&path](auto&& file) { return Closure([&path, file = std::move(file)]() mutable { EXPECT_TRUE(file.IsOpen()); EXPECT_TRUE(std::filesystem::exists(path)); return CloseFile(std::move(file)) - | Then([&path]() { + >> Then([&path]() { std::filesystem::remove(path); EXPECT_FALSE(std::filesystem::exists(path)); }); @@ -78,14 +78,14 @@ TEST_F(FilesystemTest, ReadFileSucceed) { auto e = [&]() { return OpenFile(path, UV_FS_O_RDONLY, 0) - | Then([&](File&& file) { + >> Then([&](File&& file) { return Closure([&, file = std::move(file)]() mutable { return ReadFile(file, test_string.size(), 0) - | Then([&](auto&& data) { + >> Then([&](auto&& data) { EXPECT_EQ(test_string, data); return CloseFile(std::move(file)); }) - | Then([&]() { + >> Then([&]() { std::filesystem::remove(path); EXPECT_FALSE(std::filesystem::exists(path)); }); @@ -111,10 +111,10 @@ TEST_F(FilesystemTest, ReadFileFail) { // Try to read from a File opened with WriteOnly flag. auto e = [&]() { return OpenFile(path, UV_FS_O_WRONLY, 0) - | Then([&](File&& file) { + >> Then([&](File&& file) { return Closure([&, file = std::move(file)]() mutable { return ReadFile(file, test_string.size(), 0) - | Then([&](auto&& data) { + >> Then([&](auto&& data) { EXPECT_EQ(test_string, data); return CloseFile(std::move(file)); }); @@ -142,13 +142,13 @@ TEST_F(FilesystemTest, WriteFileSucceed) { auto e = [&]() { return OpenFile(path, UV_FS_O_WRONLY, 0) - | Then([&](File&& file) { + >> Then([&](File&& file) { return Closure([&, file = std::move(file)]() mutable { return WriteFile(file, test_string, 0) - | Then([&]() { + >> Then([&]() { return CloseFile(std::move(file)); }) - | Then([&]() { + >> Then([&]() { std::ifstream ifs(path); std::string ifs_read_string; ifs_read_string.resize(test_string.size()); @@ -182,10 +182,10 @@ TEST_F(FilesystemTest, WriteFileFail) { // Try to write to a File opened with ReadOnly flag. auto e = [&]() { return OpenFile(path, UV_FS_O_RDONLY, 0) - | Then([&](File&& file) { + >> Then([&](File&& file) { return Closure([&, file = std::move(file)]() mutable { return WriteFile(file, test_string, 0) - | Then([&]() { + >> Then([&]() { return CloseFile(std::move(file)); }); }); @@ -211,7 +211,7 @@ TEST_F(FilesystemTest, UnlinkFileSucceed) { auto e = [&path]() { return UnlinkFile(path) - | Then([&]() { + >> Then([&]() { EXPECT_FALSE(std::filesystem::exists(path)); }); }; @@ -238,7 +238,7 @@ TEST_F(FilesystemTest, MakeDirectorySucceed) { auto e = [&]() { return MakeDirectory(path, 0) - | Then([&]() { + >> Then([&]() { EXPECT_TRUE(std::filesystem::exists(path)); std::filesystem::remove(path); EXPECT_FALSE(std::filesystem::exists(path)); @@ -274,7 +274,7 @@ TEST_F(FilesystemTest, RemoveDirectorySucceed) { auto e = [&]() { return RemoveDirectory(path) - | Then([&]() { + >> Then([&]() { EXPECT_FALSE(std::filesystem::exists(path)); }); }; @@ -308,7 +308,7 @@ TEST_F(FilesystemTest, CopyFileSucceed) { auto e = [&]() { return CopyFile(src, dst, 0) - | Then([&]() { + >> Then([&]() { EXPECT_TRUE(std::filesystem::exists(src)); EXPECT_TRUE(std::filesystem::exists(dst)); std::filesystem::remove(src); @@ -352,7 +352,7 @@ TEST_F(FilesystemTest, RenameFileSucceed) { auto e = [&]() { return RenameFile(src, dst) - | Then([&]() { + >> Then([&]() { EXPECT_FALSE(std::filesystem::exists(src)); EXPECT_TRUE(std::filesystem::exists(dst)); std::filesystem::remove(src); diff --git a/test/filter.cc b/test/filter.cc index 42ee7f09..24b0b0cc 100644 --- a/test/filter.cc +++ b/test/filter.cc @@ -25,18 +25,18 @@ TEST(Filter, OddLoopFlow) { auto s = [&]() { return Iterate(begin, end) - | Filter([](int x) { + >> Filter([](int x) { return x % 2 == 1; }) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(22, *s()); @@ -50,8 +50,8 @@ TEST(Filter, OddCollectFlow) { auto s = [&]() { return Iterate(begin, end) - | Filter([](int x) { return x % 2 == 1; }) - | Collect(); + >> Filter([](int x) { return x % 2 == 1; }) + >> Collect(); }; EXPECT_THAT(*s(), ElementsAre(5, 17)); @@ -63,17 +63,17 @@ TEST(Filter, OddMapLoopFlow) { auto s = [&]() { return Iterate(v) - | Filter([](int x) { return x % 2 == 1; }) - | Map([](int x) { return x + 1; }) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Filter([](int x) { return x % 2 == 1; }) + >> Map([](int x) { return x + 1; }) + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(24, *s()); @@ -85,9 +85,9 @@ TEST(Filter, OddMapCollectFlow) { auto s = [&]() { return Iterate(v) - | Filter([](int x) { return x % 2 == 1; }) - | Map([](int x) { return x + 1; }) - | Collect(); + >> Filter([](int x) { return x % 2 == 1; }) + >> Map([](int x) { return x + 1; }) + >> Collect(); }; EXPECT_THAT(*s(), UnorderedElementsAre(6, 18)); diff --git a/test/finally.cc b/test/finally.cc index 06d7541b..9429a1d7 100644 --- a/test/finally.cc +++ b/test/finally.cc @@ -21,7 +21,7 @@ using testing::ThrowsMessage; TEST(Finally, Succeed) { auto e = []() { return Just(42) - | Finally([](auto&& expected) { + >> Finally([](auto&& expected) { return Just(std::move(expected)); }); }; @@ -36,8 +36,8 @@ TEST(Finally, Succeed) { TEST(Finally, Fail) { auto e = []() { return Just(42) - | Raise("error") - | Finally([](auto&& expected) { + >> Raise("error") + >> Finally([](auto&& expected) { return Just(std::move(expected)); }); }; @@ -56,7 +56,7 @@ TEST(Finally, Stop) { return Eventual([](auto& k) { k.Stop(); }) - | Finally([](auto&& expected) { + >> Finally([](auto&& expected) { return Just(std::move(expected)); }); }; @@ -73,7 +73,7 @@ TEST(Finally, Stop) { TEST(Finally, VoidSucceed) { auto e = []() { return Just() - | Finally([](auto&& exception) { + >> Finally([](auto&& exception) { return Just(std::move(exception)); }); }; @@ -86,8 +86,8 @@ TEST(Finally, VoidSucceed) { TEST(Finally, VoidFail) { auto e = []() { return Just() - | Raise("error") - | Finally([](auto&& exception) { + >> Raise("error") + >> Finally([](auto&& exception) { return Just(std::move(exception)); }); }; @@ -106,7 +106,7 @@ TEST(Finally, VoidStop) { return Eventual([](auto& k) { k.Stop(); }) - | Finally([](auto&& exception) { + >> Finally([](auto&& exception) { return Just(std::move(exception)); }); }; @@ -123,23 +123,23 @@ TEST(Finally, VoidStop) { TEST(Finally, FinallyInsideThen) { auto e = []() { return Just(1) - | Then([](int status) { + >> Then([](int status) { return Eventual() .raises() .start([](auto& k) { k.Fail(std::runtime_error("error")); }) - | Finally([](expected&& e) { + >> Finally([](expected&& e) { return If(e.has_value()) .no([e = std::move(e)]() { return Raise(std::move(e.error())) - | Catch() - .raised( - [](std::exception&& e) { - EXPECT_STREQ( - e.what(), - "error"); - }); + >> Catch() + .raised( + [](std::exception&& e) { + EXPECT_STREQ( + e.what(), + "error"); + }); }) .yes([]() { return Raise("another error"); diff --git a/test/flat-map.cc b/test/flat-map.cc index b6db356c..68f46e87 100644 --- a/test/flat-map.cc +++ b/test/flat-map.cc @@ -29,8 +29,8 @@ using testing::ElementsAre; TEST(FlatMap, TwoLevelLoop) { auto s = []() { return Range(2) - | FlatMap([](int x) { return Range(2); }) - | Collect(); + >> FlatMap([](int x) { return Range(2); }) + >> Collect(); }; EXPECT_THAT(*s(), ElementsAre(0, 1, 0, 1)); @@ -39,9 +39,9 @@ TEST(FlatMap, TwoLevelLoop) { TEST(FlatMap, FlatMapMapped) { auto s = []() { return Range(2) - | FlatMap([](int x) { return Range(2); }) - | Map([](int x) { return x + 1; }) - | Collect(); + >> FlatMap([](int x) { return Range(2); }) + >> Map([](int x) { return x + 1; }) + >> Collect(); }; EXPECT_THAT(*s(), ElementsAre(1, 2, 1, 2)); @@ -50,12 +50,12 @@ TEST(FlatMap, FlatMapMapped) { TEST(FlatMap, FlatMapIterate) { auto s = []() { return Range(2) - | FlatMap([](int x) { + >> FlatMap([](int x) { std::vector v = {1, 2, 3}; return Iterate(std::move(v)); }) - | Map([](int x) { return x + 1; }) - | Collect(); + >> Map([](int x) { return x + 1; }) + >> Collect(); }; EXPECT_THAT(*s(), ElementsAre(2, 3, 4, 2, 3, 4)); @@ -64,7 +64,7 @@ TEST(FlatMap, FlatMapIterate) { TEST(FlatMap, TwoIndexesSum) { auto s = []() { return Range(3) - | FlatMap([](int x) { + >> FlatMap([](int x) { return Stream() .next([container = std::vector({1, 2}), i = 0u, @@ -79,7 +79,7 @@ TEST(FlatMap, TwoIndexesSum) { k.Ended(); }); }) - | Collect(); + >> Collect(); }; EXPECT_THAT(*s(), ElementsAre(1, 2, 2, 3, 3, 4)); @@ -88,11 +88,11 @@ TEST(FlatMap, TwoIndexesSum) { TEST(FlatMap, TwoIndexesSumMap) { auto s = []() { return Range(3) - | FlatMap([](int x) { + >> FlatMap([](int x) { return Range(1, 3) - | Map([x](int y) { return x + y; }); + >> Map([x](int y) { return x + y; }); }) - | Collect(); + >> Collect(); }; EXPECT_THAT(*s(), ElementsAre(1, 2, 2, 3, 3, 4)); @@ -101,13 +101,13 @@ TEST(FlatMap, TwoIndexesSumMap) { TEST(FlatMap, Let) { auto s = []() { return Iterate({1, 2}) - | FlatMap(Let([](int& x) { + >> FlatMap(Let([](int& x) { return Iterate({1, 2}) - | FlatMap(Let([&x](int& y) { + >> FlatMap(Let([&x](int& y) { return Iterate({x, y}); })); })) - | Collect(); + >> Collect(); }; EXPECT_THAT(*s(), ElementsAre(1, 1, 1, 2, 2, 1, 2, 2)); @@ -116,12 +116,12 @@ TEST(FlatMap, Let) { TEST(FlatMap, FlatMapIterateString) { auto s = []() { return Iterate(std::vector({"abc", "abc"})) - | FlatMap([](std::string x) { + >> FlatMap([](std::string x) { std::vector v = {1, 2, 3}; return Iterate(std::move(v)); }) - | Map([](int x) { return x + 1; }) - | Collect(); + >> Map([](int x) { return x + 1; }) + >> Collect(); }; EXPECT_THAT(*s(), ElementsAre(2, 3, 4, 2, 3, 4)); @@ -130,9 +130,9 @@ TEST(FlatMap, FlatMapIterateString) { TEST(FlatMap, ThreeLevelLoop) { auto s = []() { return Range(2) - | FlatMap([](int x) { return Range(2); }) - | FlatMap([](int x) { return Range(2); }) - | Collect(); + >> FlatMap([](int x) { return Range(2); }) + >> FlatMap([](int x) { return Range(2); }) + >> Collect(); }; EXPECT_THAT(*s(), ElementsAre(0, 1, 0, 1, 0, 1, 0, 1)); @@ -141,13 +141,13 @@ TEST(FlatMap, ThreeLevelLoop) { TEST(FlatMap, ThreeLevelLoopInside) { auto s = []() { return Range(2) - | FlatMap([](int x) { + >> FlatMap([](int x) { return Range(2) - | FlatMap([](int y) { + >> FlatMap([](int y) { return Range(2); }); }) - | Collect(); + >> Collect(); }; EXPECT_THAT(*s(), ElementsAre(0, 1, 0, 1, 0, 1, 0, 1)); @@ -156,15 +156,15 @@ TEST(FlatMap, ThreeLevelLoopInside) { TEST(FlatMap, ThreeIndexesSumMap) { auto s = []() { return Range(3) - | FlatMap([](int x) { + >> FlatMap([](int x) { return Range(1, 3) - | Map([x](int y) { return x + y; }); + >> Map([x](int y) { return x + y; }); }) - | FlatMap([](int sum) { + >> FlatMap([](int sum) { return Range(1, 3) - | Map([sum](int z) { return sum + z; }); + >> Map([sum](int z) { return sum + z; }); }) - | Collect(); + >> Collect(); }; EXPECT_THAT(*s(), ElementsAre(2, 3, 3, 4, 3, 4, 4, 5, 4, 5, 5, 6)); @@ -174,14 +174,14 @@ TEST(FlatMap, ThreeIndexesSumMap) { TEST(FlatMap, VectorVector) { auto s = []() { return Iterate(std::vector({2, 3, 14})) - | FlatMap([](int x) { + >> FlatMap([](int x) { std::vector> c; c.push_back(std::vector()); c.push_back(std::vector()); return Iterate(std::move(c)); }) - | FlatMap([](std::vector x) { return Range(2); }) - | Collect(); + >> FlatMap([](std::vector x) { return Range(2); }) + >> Collect(); }; EXPECT_THAT(*s(), ElementsAre(0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1)); @@ -192,15 +192,15 @@ class FlatMapTest : public EventLoopTest {}; TEST_F(FlatMapTest, Interrupt) { auto e = []() { return Iterate(std::vector(1000)) - | Map([](int x) { + >> Map([](int x) { return Timer(std::chrono::milliseconds(100)) - | Just(x); + >> Just(x); }) - | FlatMap([](int x) { return Iterate({1, 2}); }) - | Collect>() - .stop([](auto& collection, auto& k) { - k.Start(std::move(collection)); - }); + >> FlatMap([](int x) { return Iterate({1, 2}); }) + >> Collect>() + .stop([](auto& collection, auto& k) { + k.Start(std::move(collection)); + }); }; auto [future, k] = PromisifyForTest(e()); @@ -225,7 +225,7 @@ TEST(FlatMap, InterruptReturn) { auto e = [&]() { return Iterate(std::vector(1000)) - | FlatMap([&](int x) { + >> FlatMap([&](int x) { return Stream() .interruptible() .begin([&](auto& k, auto& handler) { @@ -239,7 +239,7 @@ TEST(FlatMap, InterruptReturn) { k.Ended(); }); }) - | Collect(); + >> Collect(); }; auto [future, k] = PromisifyForTest(e()); diff --git a/test/foreach.cc b/test/foreach.cc index c27caab2..c4931ae3 100644 --- a/test/foreach.cc +++ b/test/foreach.cc @@ -20,7 +20,7 @@ TEST(Foreach, Test) { [&](int i) { v.push_back(i); }) - | Then([&]() { + >> Then([&]() { return std::move(v); }); }); diff --git a/test/generator.cc b/test/generator.cc index 910b09ed..766d2a17 100644 --- a/test/generator.cc +++ b/test/generator.cc @@ -39,30 +39,30 @@ TEST(Generator, Succeed) { auto e1 = [&]() { return stream() - | Collect(); + >> Collect(); }; EXPECT_THAT(*e1(), ElementsAre(1, 2, 3)); auto e2 = [&]() { return stream() - | Loop() - .body([](auto& k, auto&&) { - k.Done(); - }) - .ended([](auto& k) { - k.Start(0); - }); + >> Loop() + .body([](auto& k, auto&&) { + k.Done(); + }) + .ended([](auto& k) { + k.Start(0); + }); }; EXPECT_EQ(*e2(), 0); auto e3 = [&stream]() { return stream() - | Map([](auto x) { + >> Map([](auto x) { return x + 1; }) - | Collect(); + >> Collect(); }; EXPECT_THAT(*e3(), ElementsAre(2, 3, 4)); @@ -77,7 +77,7 @@ TEST(Generator, Succeed) { auto e4 = [&stream2]() { return stream2() - | Collect(); + >> Collect(); }; EXPECT_THAT(*e4(), ElementsAre(1, 2, 3)); @@ -101,15 +101,15 @@ TEST(Generator, GeneratorWithNonCopyable) { auto e = [&]() { return generator() - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(*e(), 100); @@ -131,15 +131,15 @@ TEST(Generator, GeneratorWithPtr) { auto e = [&]() { return generator() - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(*e(), 100); @@ -193,20 +193,20 @@ TEST(Generator, InterruptStream) { auto e = [&]() { return stream() - | Loop() - .body([&](auto& k, auto&&) { - interrupt.Trigger(); - }) - .ended([&](auto&) { - functions.ended.Call(); - }) - .fail([&](auto&, auto&&) { - functions.fail.Call(); - }) - .stop([&](auto& k) { - functions.stop.Call(); - k.Stop(); - }); + >> Loop() + .body([&](auto& k, auto&&) { + interrupt.Trigger(); + }) + .ended([&](auto&) { + functions.ended.Call(); + }) + .fail([&](auto&, auto&&) { + functions.fail.Call(); + }) + .stop([&](auto& k) { + functions.stop.Call(); + k.Stop(); + }); }; auto [future, k] = PromisifyForTest(e()); @@ -271,23 +271,23 @@ TEST(Generator, FailStream) { .start([](auto& k) { k.Fail(std::runtime_error("error")); }) - | stream() - | Loop() - .body([&](auto& k, auto&&) { - functions.body.Call(); - }) - .ended([&](auto&) { - functions.ended.Call(); - }) - .fail([&](auto& k, auto&& error) { - // No need to specify 'raises' because type of error is - // 'std::exception_ptr', that just propagates. - functions.fail.Call(); - k.Fail(std::forward(error)); - }) - .stop([&](auto& k) { - functions.stop.Call(); - }); + >> stream() + >> Loop() + .body([&](auto& k, auto&&) { + functions.body.Call(); + }) + .ended([&](auto&) { + functions.ended.Call(); + }) + .fail([&](auto& k, auto&& error) { + // No need to specify 'raises' because type of error is + // 'std::exception_ptr', that just propagates. + functions.fail.Call(); + k.Fail(std::forward(error)); + }) + .stop([&](auto& k) { + functions.stop.Call(); + }); }; auto [future, k] = PromisifyForTest(e()); @@ -358,21 +358,21 @@ TEST(Generator, StopStream) { .start([](auto& k) { k.Stop(); }) - | stream() - | Loop() - .body([&](auto& k, auto&&) { - functions.body.Call(); - }) - .ended([&](auto&) { - functions.ended.Call(); - }) - .fail([&](auto& k, auto&& error) { - functions.fail.Call(); - }) - .stop([&](auto& k) { - functions.stop.Call(); - k.Stop(); - }); + >> stream() + >> Loop() + .body([&](auto& k, auto&&) { + functions.body.Call(); + }) + .ended([&](auto&) { + functions.ended.Call(); + }) + .fail([&](auto& k, auto&& error) { + functions.fail.Call(); + }) + .stop([&](auto& k) { + functions.stop.Call(); + k.Stop(); + }); }; auto [future, k] = PromisifyForTest(e()); @@ -392,7 +392,7 @@ TEST(Generator, TaskWithGenerator) { auto task = [&]() -> Task::Of> { return [&]() { return stream() - | Collect(); + >> Collect(); }; }; @@ -439,15 +439,15 @@ TEST(Generator, Void) { auto e = [&]() { return stream() - | Loop() - .body([&](auto& stream) { - functions.body.Call(); - stream.Done(); - }) - .ended([&](auto& k) { - functions.ended.Call(); - k.Start(); - }); + >> Loop() + .body([&](auto& stream) { + functions.body.Call(); + stream.Done(); + }) + .ended([&](auto& k) { + functions.ended.Call(); + k.Start(); + }); }; *e(); @@ -457,7 +457,7 @@ TEST(Generator, FlatMap) { auto stream = []() -> Generator::Of { return []() { return Iterate({1, 2, 3}) - | FlatMap([](int i) { + >> FlatMap([](int i) { return Range(0, i); }); }; @@ -465,7 +465,7 @@ TEST(Generator, FlatMap) { auto e = [&]() { return stream() - | Collect(); + >> Collect(); }; EXPECT_THAT(*e(), ElementsAre(0, 0, 1, 0, 1, 2)); @@ -481,7 +481,7 @@ TEST(Generator, ConstRef) { auto e = [&]() { return stream() - | Collect(); + >> Collect(); }; EXPECT_THAT(*e(), ElementsAre(1, 2, 3)); @@ -498,7 +498,7 @@ TEST(Generator, FromTo) { } }); }) - | Closure([&]() { + >> Closure([&]() { return Iterate(std::move(data)); }); }); @@ -506,8 +506,8 @@ TEST(Generator, FromTo) { auto e = [&]() { return Just(std::string("123")) - | stream() - | Collect(); + >> stream() + >> Collect(); }; EXPECT_THAT(*e(), ElementsAre(1, 2, 3)); @@ -524,14 +524,14 @@ TEST(Generator, FromToLValue) { } }); }) - | Iterate(data); + >> Iterate(data); }); }; auto e = [&]() { return Just(std::string("123")) - | stream() - | Collect(); + >> stream() + >> Collect(); }; EXPECT_THAT(*e(), ElementsAre(1, 2, 3)); @@ -550,7 +550,7 @@ TEST(Generator, Raises) { auto e = [&]() { return stream() - | Collect(); + >> Collect(); }; static_assert( diff --git a/test/grpc/accept.cc b/test/grpc/accept.cc index 323ebb58..dd16c2bf 100644 --- a/test/grpc/accept.cc +++ b/test/grpc/accept.cc @@ -36,7 +36,7 @@ TEST(AcceptTest, ServeValidate) { keyvaluestore::KeyValueStore, keyvaluestore::Request, Stream>("GetValues") - | Head(); + >> Head(); }; EXPECT_THAT( @@ -51,7 +51,7 @@ TEST(AcceptTest, ServeValidate) { keyvaluestore::KeyValueStore, Stream, keyvaluestore::Response>("GetValues") - | Head(); + >> Head(); }; EXPECT_THAT( @@ -64,7 +64,7 @@ TEST(AcceptTest, ServeValidate) { auto serve = [&]() { return server->Accept, HelloReply>( "SayHello") - | Head(); + >> Head(); }; EXPECT_THAT( @@ -77,7 +77,7 @@ TEST(AcceptTest, ServeValidate) { auto serve = [&]() { return server->Accept>( "SayHello") - | Head(); + >> Head(); }; EXPECT_THAT( @@ -92,7 +92,7 @@ TEST(AcceptTest, ServeValidate) { keyvaluestore::KeyValueStore, Stream, Stream>("GetValues") - | Head(); + >> Head(); }; EXPECT_THAT( @@ -107,7 +107,7 @@ TEST(AcceptTest, ServeValidate) { keyvaluestore::KeyValueStore, Stream, Stream>("GetValues") - | Head(); + >> Head(); }; EXPECT_THAT( diff --git a/test/grpc/cancelled-by-client.cc b/test/grpc/cancelled-by-client.cc index 046d6eb9..a5507fbd 100644 --- a/test/grpc/cancelled-by-client.cc +++ b/test/grpc/cancelled-by-client.cc @@ -37,8 +37,8 @@ TEST(CancelledByClientTest, Cancelled) { auto serve = [&]() { return server->Accept("SayHello") - | Head() - | Then(Let([](auto& call) { + >> Head() + >> Then(Let([](auto& call) { return call.WaitForDone(); })); }; @@ -56,7 +56,7 @@ TEST(CancelledByClientTest, Cancelled) { auto call = [&]() { return client.Call("SayHello") - | Then(Let([&](auto& call) { + >> Then(Let([&](auto& call) { call.context()->TryCancel(); return call.Finish(); })); diff --git a/test/grpc/cancelled-by-server.cc b/test/grpc/cancelled-by-server.cc index 596ea8ce..9c9975c4 100644 --- a/test/grpc/cancelled-by-server.cc +++ b/test/grpc/cancelled-by-server.cc @@ -37,8 +37,8 @@ TEST(CancelledByServerTest, Cancelled) { auto serve = [&]() { return server->Accept("SayHello") - | Head() - | Then(Let([](auto& call) { + >> Head() + >> Then(Let([](auto& call) { call.context()->TryCancel(); return call.WaitForDone(); })); @@ -59,9 +59,9 @@ TEST(CancelledByServerTest, Cancelled) { auto call = [&]() { return client.Call("SayHello", &context) - | Then(Let([](auto& call) { + >> Then(Let([](auto& call) { return call.WritesDone() - | call.Finish(); + >> call.Finish(); })); }; diff --git a/test/grpc/client-death-test.cc b/test/grpc/client-death-test.cc index 110ec74d..62985c56 100644 --- a/test/grpc/client-death-test.cc +++ b/test/grpc/client-death-test.cc @@ -42,8 +42,8 @@ TEST(ClientDeathTest, ServerHandlesClientDisconnect) { auto serve = [&]() { return server->Accept("SayHello") - | Head() - | Then(Let([](auto& call) { + >> Head() + >> Then(Let([](auto& call) { return call.WaitForDone(); })); }; diff --git a/test/grpc/deadline.cc b/test/grpc/deadline.cc index 990d6a8d..3f433638 100644 --- a/test/grpc/deadline.cc +++ b/test/grpc/deadline.cc @@ -38,8 +38,8 @@ TEST(DeadlineTest, DeadlineExceeded) { auto serve = [&]() { return server->Accept("SayHello") - | Head() - | Then(Let([](auto& call) { + >> Head() + >> Then(Let([](auto& call) { return call.WaitForDone(); })); }; @@ -57,18 +57,18 @@ TEST(DeadlineTest, DeadlineExceeded) { auto call = [&]() { return client.Context() - | Then([&](auto* context) { + >> Then([&](auto* context) { auto now = std::chrono::system_clock::now(); context->set_deadline(now + std::chrono::milliseconds(100)); return client.Call( "SayHello", context) - | Then(Let([](auto& call) { + >> Then(Let([](auto& call) { HelloRequest request; request.set_name("emily"); return call.Writer().WriteLast(request) - | call.Finish(); + >> call.Finish(); })); }); }; diff --git a/test/grpc/death-client.cc b/test/grpc/death-client.cc index bca43950..79ef99b6 100644 --- a/test/grpc/death-client.cc +++ b/test/grpc/death-client.cc @@ -23,7 +23,7 @@ void RunClient(const int port) { auto call = [&]() { return client.Call("SayHello") - | Then([](auto&& call) { + >> Then([](auto&& call) { // NOTE: need to use 'std::_Exit()' to avoid deadlock // waiting for borrowed contexts to get relinquished. std::_Exit(kProcessIntentionalExitCode); diff --git a/test/grpc/death-server.cc b/test/grpc/death-server.cc index d3467f0a..965462af 100644 --- a/test/grpc/death-server.cc +++ b/test/grpc/death-server.cc @@ -36,8 +36,8 @@ void RunServer(const int pipe) { auto serve = [&]() { return server->Accept("SayHello") - | Head() - | Then([](auto&& call) { + >> Head() + >> Then([](auto&& call) { // NOTE: need to use 'std::_Exit()' to avoid deadlock // waiting for borrowed contexts to get relinquished. std::_Exit(kProcessIntentionalExitCode); diff --git a/test/grpc/greeter-server.cc b/test/grpc/greeter-server.cc index 183d3319..4a552ed1 100644 --- a/test/grpc/greeter-server.cc +++ b/test/grpc/greeter-server.cc @@ -60,16 +60,16 @@ TEST(GreeterServerTest, SayHello) { auto call = [&]() { return client.Call("SayHello") - | Then(Let([](auto& call) { + >> Then(Let([](auto& call) { HelloRequest request; request.set_name("emily"); return call.Writer().WriteLast(request) - | call.Reader().Read() - | Map([](auto&& response) { + >> call.Reader().Read() + >> Map([](auto&& response) { EXPECT_EQ("Hello emily", response.message()); }) - | Loop() - | call.Finish(); + >> Loop() + >> call.Finish(); })); }; diff --git a/test/grpc/helloworld.eventuals.cc b/test/grpc/helloworld.eventuals.cc index 1b09963e..a95027e3 100644 --- a/test/grpc/helloworld.eventuals.cc +++ b/test/grpc/helloworld.eventuals.cc @@ -35,10 +35,10 @@ Task::Of Greeter::TypeErasedService::Serve() { helloworld::Greeter, helloworld::HelloRequest, helloworld::HelloReply>("SayHello") - | Concurrent([this]() { + >> Concurrent([this]() { return Map(Let([this](auto& call) { return UnaryPrologue(call) - | Then(Let([&](auto& request) { + >> Then(Let([&](auto& request) { return Then( [&, // NOTE: using a tuple because need @@ -51,13 +51,13 @@ Task::Of Greeter::TypeErasedService::Serve() { call.context(), &request}]() mutable { return TypeErasedSayHello(&args) - | UnaryEpilogue(call); + >> UnaryEpilogue(call); }); })); })); }) - | Loop()) - | Just(); // Return 'void'. + >> Loop()) + >> Just(); // Return 'void'. }; } diff --git a/test/grpc/multiple-hosts.cc b/test/grpc/multiple-hosts.cc index 9c0ddecd..fa546ce3 100644 --- a/test/grpc/multiple-hosts.cc +++ b/test/grpc/multiple-hosts.cc @@ -37,17 +37,17 @@ TEST(MultipleHostsTest, Success) { auto serve = [&](auto&& host) { return server->Accept("SayHello", host) - | Head() - | Then(Let([](auto& call) { + >> Head() + >> Then(Let([](auto& call) { return call.Reader().Read() - | Head() // Only get the first element. - | Then([](auto&& request) { + >> Head() // Only get the first element. + >> Then([](auto&& request) { HelloReply reply; std::string prefix("Hello "); reply.set_message(prefix + request.name()); return reply; }) - | UnaryEpilogue(call); + >> UnaryEpilogue(call); })); }; @@ -68,13 +68,13 @@ TEST(MultipleHostsTest, Success) { auto call = [&](auto&& host) { return client.Call("SayHello", host) - | Then(Let([](auto& call) { + >> Then(Let([](auto& call) { HelloRequest request; request.set_name("Emily"); return call.Writer().WriteLast(request) - | call.Reader().Read() - | Head() // Expecting but ignoring the response. - | call.Finish(); + >> call.Reader().Read() + >> Head() // Expecting but ignoring the response. + >> call.Finish(); })); }; diff --git a/test/grpc/server-death-test.cc b/test/grpc/server-death-test.cc index 6dd913cd..eebfbb92 100644 --- a/test/grpc/server-death-test.cc +++ b/test/grpc/server-death-test.cc @@ -64,11 +64,11 @@ TEST(ServerDeathTest, ClientReceivesUnavailable) { auto call = [&]() { return client.Call("SayHello") - | Then(Let([](ClientCall& call) { + >> Then(Let([](ClientCall& call) { HelloRequest request; request.set_name("emily"); return call.Writer().WriteLast(request) - | Finally( + >> Finally( [&](expected&&) { return call.Finish(); }); diff --git a/test/grpc/server-unavailable.cc b/test/grpc/server-unavailable.cc index 2027f6cc..5a81fc0c 100644 --- a/test/grpc/server-unavailable.cc +++ b/test/grpc/server-unavailable.cc @@ -30,7 +30,7 @@ TEST(ServerUnavailableTest, NonexistantServer) { auto call = [&]() { return client.Call("SayHello") - | Then(Let([](auto& call) { + >> Then(Let([](auto& call) { return call.Finish(); })); }; diff --git a/test/grpc/streaming.cc b/test/grpc/streaming.cc index fc7f1a11..f4b46cb5 100644 --- a/test/grpc/streaming.cc +++ b/test/grpc/streaming.cc @@ -61,16 +61,16 @@ void test_client_behavior(Handler handler) { Stream, Stream>( "keyvaluestore.KeyValueStore.GetValues") - | Head() - | Then(Let([](auto& call) { + >> Head() + >> Then(Let([](auto& call) { return call.Reader().Read() - | Map([&](auto&& request) { + >> Map([&](auto&& request) { keyvaluestore::Response response; response.set_value(request.key()); return call.Writer().Write(response); }) - | Loop() - | Closure([]() { + >> Loop() + >> Closure([]() { std::vector responses; for (size_t i = 0; i < 3; i++) { keyvaluestore::Response response; @@ -79,7 +79,7 @@ void test_client_behavior(Handler handler) { } return Iterate(std::move(responses)); }) - | StreamingEpilogue(call); + >> StreamingEpilogue(call); })); }; @@ -99,7 +99,7 @@ void test_client_behavior(Handler handler) { Stream, Stream>( "keyvaluestore.KeyValueStore.GetValues") - | std::move(handler); + >> std::move(handler); }; auto status = *call(); @@ -116,35 +116,35 @@ TEST(StreamingTest, WriteLast_AfterReply_TwoRequests) { keyvaluestore::Request request; request.set_key("1"); return call.Writer().Write(request) - | call.Reader().Read() - | Head() - | Then([&](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([&](auto&& response) { EXPECT_EQ("1", response.value()); keyvaluestore::Request request; request.set_key("2"); return call.Writer().WriteLast(request); }) - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("2", response.value()); }) - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("10", response.value()); }) - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("11", response.value()); }) - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("12", response.value()); }) - | call.Finish(); + >> call.Finish(); }))); } @@ -154,27 +154,27 @@ TEST(StreamingTest, WriteLast_BeforeReply_OneRequest) { keyvaluestore::Request request; request.set_key("1"); return call.Writer().WriteLast(request) - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("1", response.value()); }) - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("10", response.value()); }) - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("11", response.value()); }) - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("12", response.value()); }) - | call.Finish(); + >> call.Finish(); }))); } @@ -184,37 +184,37 @@ TEST(StreamingTest, WriteLast_BeforeReply_TwoRequests) { keyvaluestore::Request request1; request1.set_key("1"); return call.Writer().Write(request1) - | Then([&]() { + >> Then([&]() { keyvaluestore::Request request2; request2.set_key("2"); return call.Writer().WriteLast(request2); }) - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("1", response.value()); }) - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("2", response.value()); }) - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("10", response.value()); }) - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("11", response.value()); }) - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("12", response.value()); }) - | call.Finish(); + >> call.Finish(); }))); } @@ -224,28 +224,28 @@ TEST(StreamingTest, WritesDone_AfterReply_OneRequest) { keyvaluestore::Request request; request.set_key("1"); return call.Writer().Write(request) - | call.Reader().Read() - | Head() - | Then([&](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([&](auto&& response) { EXPECT_EQ("1", response.value()); return call.WritesDone(); }) - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("10", response.value()); }) - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("11", response.value()); }) - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("12", response.value()); }) - | call.Finish(); + >> call.Finish(); }))); } @@ -255,36 +255,36 @@ TEST(StreamingTest, WritesDone_AfterReply_TwoRequests) { keyvaluestore::Request request; request.set_key("1"); return call.Writer().Write(request) - | call.Reader().Read() - | Head() - | Then([&](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([&](auto&& response) { EXPECT_EQ("1", response.value()); keyvaluestore::Request request; request.set_key("2"); return call.Writer().Write(request); }) - | call.Reader().Read() - | Head() - | Then([&](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([&](auto&& response) { EXPECT_EQ("2", response.value()); return call.WritesDone(); }) - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("10", response.value()); }) - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("11", response.value()); }) - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("12", response.value()); }) - | call.Finish(); + >> call.Finish(); }))); } @@ -294,28 +294,28 @@ TEST(StreamingTest, WritesDone_BeforeReply_OneRequest) { keyvaluestore::Request request1; request1.set_key("1"); return call.Writer().Write(request1) - | call.WritesDone() - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.WritesDone() + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("1", response.value()); }) - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("10", response.value()); }) - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("11", response.value()); }) - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("12", response.value()); }) - | call.Finish(); + >> call.Finish(); }))); } @@ -325,38 +325,38 @@ TEST(StreamingTest, WritesDone_BeforeReply_TwoRequests) { keyvaluestore::Request request1; request1.set_key("1"); return call.Writer().Write(request1) - | Then([&]() { + >> Then([&]() { keyvaluestore::Request request2; request2.set_key("2"); return call.Writer().Write(request2) - | call.WritesDone(); + >> call.WritesDone(); }) - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("1", response.value()); }) - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("2", response.value()); }) - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("10", response.value()); }) - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("11", response.value()); }) - | call.Reader().Read() - | Head() - | Then([](auto&& response) { + >> call.Reader().Read() + >> Head() + >> Then([](auto&& response) { EXPECT_EQ("12", response.value()); }) - | call.Finish(); + >> call.Finish(); }))); } diff --git a/test/grpc/unary.cc b/test/grpc/unary.cc index 6104ff0d..98ebf8f9 100644 --- a/test/grpc/unary.cc +++ b/test/grpc/unary.cc @@ -41,17 +41,17 @@ void TestUnaryWithClient( auto serve = [&]() { return server->Accept("SayHello") - | Head() - | Then(Let([](auto& call) { + >> Head() + >> Then(Let([](auto& call) { return call.Reader().Read() - | Head() // Only get the first element. - | Then([](auto&& request) { + >> Head() // Only get the first element. + >> Then([](auto&& request) { HelloReply reply; std::string prefix("Hello "); reply.set_message(prefix + request.name()); return reply; }) - | UnaryEpilogue(call); + >> UnaryEpilogue(call); })); }; @@ -64,16 +64,16 @@ void TestUnaryWithClient( auto call = [&]() { return client.Call("SayHello") - | Then(Let([](auto& call) { + >> Then(Let([](auto& call) { HelloRequest request; request.set_name("emily"); return call.Writer().WriteLast(request) - | call.Reader().Read() - | Map([](auto&& response) { + >> call.Reader().Read() + >> Map([](auto&& response) { EXPECT_EQ("Hello emily", response.message()); }) - | Loop() - | call.Finish(); + >> Loop() + >> call.Finish(); })); }; diff --git a/test/grpc/unimplemented.cc b/test/grpc/unimplemented.cc index bd4c4391..1c0b2e8b 100644 --- a/test/grpc/unimplemented.cc +++ b/test/grpc/unimplemented.cc @@ -42,7 +42,7 @@ TEST(UnimplementedTest, ClientCallsUnimplementedServerMethod) { auto call = [&]() { return client.Call("SayHello") - | Then(Let([](auto& call) { + >> Then(Let([](auto& call) { return call.Finish(); })); }; diff --git a/test/http.cc b/test/http.cc index 6c6a5522..6a161410 100644 --- a/test/http.cc +++ b/test/http.cc @@ -95,9 +95,9 @@ TEST_P(HttpTest, GetGet) { auto e = [&]() { return client.Get(server.uri()) - | Then(Let([&](auto& response1) { + >> Then(Let([&](auto& response1) { return client.Get(server.uri()) - | Then([&](auto&& response2) { + >> Then([&](auto&& response2) { return std::tuple{response1, response2}; }); })); diff --git a/test/if.cc b/test/if.cc index c95bc498..dd01f435 100644 --- a/test/if.cc +++ b/test/if.cc @@ -19,7 +19,7 @@ using testing::ThrowsMessage; TEST(IfTest, Yes) { auto e = []() { return Just(1) - | Then([](int i) { + >> Then([](int i) { return If(i == 1) .yes([]() { return Just("yes"); }) .no([]() { return Just("no"); }); @@ -38,7 +38,7 @@ TEST(IfTest, Yes) { TEST(IfTest, No) { auto e = []() { return Just(0) - | Then([](int i) { + >> Then([](int i) { return If(i == 1) .yes([]() { return Just("yes"); }) .no([]() { return Just("no"); }); @@ -52,8 +52,8 @@ TEST(IfTest, No) { TEST(IfTest, Fail) { auto e = []() { return Just(0) - | Raise("error") - | Then([](int i) { + >> Raise("error") + >> Then([](int i) { return If(i == 1) .yes([]() { return Just("yes"); }) .no([]() { return Just("no"); }); @@ -77,7 +77,7 @@ TEST(IfTest, Interrupt) { auto e = [&]() { return Just(1) - | Then([&](int i) { + >> Then([&](int i) { return If(i == 1) .yes([&]() { return Eventual() @@ -115,7 +115,7 @@ TEST(IfTest, Interrupt) { TEST(IfTest, Raise) { auto e = []() { return Just(1) - | Then([](int i) { + >> Then([](int i) { return If(i == 1) .yes([]() { return 42; }) .no([]() { return Raise("raise"); }); diff --git a/test/iterate.cc b/test/iterate.cc index 1b6f933b..693fd303 100644 --- a/test/iterate.cc +++ b/test/iterate.cc @@ -26,15 +26,15 @@ TEST(Iterate, VectorLvalue) { auto s = [&]() { return Iterate(v) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -46,15 +46,15 @@ TEST(Iterate, VectorBeginEnd) { auto s = [&]() { return Iterate(v.begin(), v.end() - 1) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(5, *s()); @@ -64,15 +64,15 @@ TEST(Iterate, VectorBeginEnd) { TEST(Iterate, VectorRvalue) { auto s = [&]() { return Iterate(std::vector({5, 12})) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -84,15 +84,15 @@ TEST(Iterate, VectorMove) { auto s = [&]() { return Iterate(std::move(v)) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -105,15 +105,15 @@ TEST(Iterate, SetLvalue) { auto s = [&]() { return Iterate(container) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -125,15 +125,15 @@ TEST(Iterate, SetBeginEnd) { auto s = [&]() { return Iterate(container.begin(), container.end()) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -143,15 +143,15 @@ TEST(Iterate, SetBeginEnd) { TEST(Iterate, SetRvalue) { auto s = [&]() { return Iterate(std::set({5, 12})) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -163,15 +163,15 @@ TEST(Iterate, SetMove) { auto s = [&]() { return Iterate(std::move(container)) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -184,15 +184,15 @@ TEST(Iterate, ListLvalue) { auto s = [&]() { return Iterate(container) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -204,15 +204,15 @@ TEST(Iterate, ListBeginEnd) { auto s = [&]() { return Iterate(container.begin(), container.end()) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -222,15 +222,15 @@ TEST(Iterate, ListBeginEnd) { TEST(Iterate, ListRvalue) { auto s = [&]() { return Iterate(std::list({5, 12})) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -242,15 +242,15 @@ TEST(Iterate, ListMove) { auto s = [&]() { return Iterate(std::move(container)) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -263,15 +263,15 @@ TEST(Iterate, DequeLvalue) { auto s = [&]() { return Iterate(container) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -283,15 +283,15 @@ TEST(Iterate, DequeBeginEnd) { auto s = [&]() { return Iterate(container.begin() + 1, container.end()) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(12, *s()); @@ -301,15 +301,15 @@ TEST(Iterate, DequeBeginEnd) { TEST(Iterate, DequeRvalue) { auto s = [&]() { return Iterate(std::deque({5, 12})) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -321,15 +321,15 @@ TEST(Iterate, DequeMove) { auto s = [&]() { return Iterate(std::move(container)) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -342,15 +342,15 @@ TEST(Iterate, MapLvalue) { auto s = [&]() { return Iterate(container) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value.second; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value.second; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -362,15 +362,15 @@ TEST(Iterate, MapBeginEnd) { auto s = [&]() { return Iterate(container.begin(), container.end()) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value.second; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value.second; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -380,15 +380,15 @@ TEST(Iterate, MapBeginEnd) { TEST(Iterate, MapRvalue) { auto s = [&]() { return Iterate(std::map{{1, 5}, {2, 12}}) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value.second; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value.second; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -400,15 +400,15 @@ TEST(Iterate, MapMove) { auto s = [&]() { return Iterate(std::move(container)) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value.second; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value.second; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -421,15 +421,15 @@ TEST(Iterate, UnorderedSetLvalue) { auto s = [&]() { return Iterate(container) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -441,15 +441,15 @@ TEST(Iterate, UnorderedSetBeginEnd) { auto s = [&]() { return Iterate(container.begin(), container.end()) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -459,15 +459,15 @@ TEST(Iterate, UnorderedSetBeginEnd) { TEST(Iterate, UnorderedSetRvalue) { auto s = [&]() { return Iterate(std::unordered_set{5, 12}) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -479,15 +479,15 @@ TEST(Iterate, UnorderedSetMove) { auto s = [&]() { return Iterate(std::move(container)) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -500,15 +500,15 @@ TEST(Iterate, UnorderedMapLvalue) { auto s = [&]() { return Iterate(container) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value.second; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value.second; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -520,15 +520,15 @@ TEST(Iterate, UnorderedMapBeginEnd) { auto s = [&]() { return Iterate(container.begin(), container.end()) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value.second; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value.second; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -538,15 +538,15 @@ TEST(Iterate, UnorderedMapBeginEnd) { TEST(Iterate, UnorderedMapRvalue) { auto s = [&]() { return Iterate(std::unordered_map{{1, 5}, {2, 12}}) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value.second; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value.second; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -558,15 +558,15 @@ TEST(Iterate, UnorderedMapMove) { auto s = [&]() { return Iterate(std::move(container)) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value.second; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value.second; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -579,15 +579,15 @@ TEST(Iterate, ArrayLvalue) { auto s = [&]() { return Iterate(container) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -599,15 +599,15 @@ TEST(Iterate, ArrayBeginEnd) { auto s = [&]() { return Iterate(container.begin(), container.end() - 1) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(5, *s()); @@ -617,15 +617,15 @@ TEST(Iterate, ArrayBeginEnd) { TEST(Iterate, ArrayRvalue) { auto s = [&]() { return Iterate(std::array({5, 12})) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -637,15 +637,15 @@ TEST(Iterate, ArrayMove) { auto s = [&]() { return Iterate(std::move(container)) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -657,15 +657,15 @@ TEST(Iterate, ArrayStringMove) { auto s = [&]() { return Iterate(std::move(container)) - | Loop() - .context(std::string("")) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(std::string("")) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ("HelloWorld", *s()); @@ -679,15 +679,15 @@ TEST(Iterate, CommonArrayPointer) { auto s = [&]() { return Iterate(&container[0], &container[1] + 1) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -699,15 +699,15 @@ TEST(Iterate, CommonArraySize) { auto s = [&]() { return Iterate(container, 2) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(17, *s()); @@ -719,18 +719,18 @@ TEST(Iterate, VectorStringConcatenate) { auto s = [&]() { return Iterate(container) - | Loop() - .context(std::string("")) - .body([](auto& s, auto& stream, auto&& value) { - if (!s.empty()) { - s += ' '; - } - s += value; - stream.Next(); - }) - .ended([](auto& s, auto& k) { - k.Start(s); - }); + >> Loop() + .context(std::string("")) + .body([](auto& s, auto& stream, auto&& value) { + if (!s.empty()) { + s += ' '; + } + s += value; + stream.Next(); + }) + .ended([](auto& s, auto& k) { + k.Start(s); + }); }; EXPECT_EQ("Hello World !", *s()); @@ -742,18 +742,18 @@ TEST(Iterate, VectorStringContcatenatePartial) { auto s = [&]() { return Iterate(container.begin() + 2, container.end() - 1) - | Loop() - .context(std::string("")) - .body([](auto& s, auto& stream, auto&& value) { - if (!s.empty()) { - s += ' '; - } - s += value; - stream.Next(); - }) - .ended([](auto& s, auto& k) { - k.Start(s); - }); + >> Loop() + .context(std::string("")) + .body([](auto& s, auto& stream, auto&& value) { + if (!s.empty()) { + s += ' '; + } + s += value; + stream.Next(); + }) + .ended([](auto& s, auto& k) { + k.Start(s); + }); }; EXPECT_EQ("Hello World", *s()); @@ -762,15 +762,15 @@ TEST(Iterate, VectorStringContcatenatePartial) { TEST(Iterate, InitializerList) { auto s = []() { return Iterate({5, 12, 13}) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(30, *s()); @@ -784,11 +784,11 @@ TEST(Iterate, UniquePtr) { auto s = [&]() { return Iterate(v) - | Map([](auto& i) -> decltype(i) { + >> Map([](auto& i) -> decltype(i) { (*i)++; return i; }) - | Reduce( + >> Reduce( /* sum = */ 0, [](auto& sum) { return Then([&](auto& i) { diff --git a/test/just.cc b/test/just.cc index 8084878f..be02e2a4 100644 --- a/test/just.cc +++ b/test/just.cc @@ -22,7 +22,7 @@ TEST(JustTest, Void) { bool ran = false; auto e = [&]() { return Just() - | Then([&]() { + >> Then([&]() { ran = true; }); }; @@ -38,7 +38,7 @@ TEST(JustTest, Ref) { auto e = [&]() { return Just(std::ref(x)) - | Then([](int& x) { + >> Then([](int& x) { x += 100; }); }; @@ -52,7 +52,7 @@ TEST(JustTest, ConstRef) { auto e = [&]() { return Just(std::cref(x)) - | Then([](const int& x) { + >> Then([](const int& x) { return std::cref(x); }); }; diff --git a/test/let.cc b/test/let.cc index cef7f650..825c88b1 100644 --- a/test/let.cc +++ b/test/let.cc @@ -20,12 +20,12 @@ TEST_F(LetTest, Let) { auto e = []() { return Just(Foo{41}) - | Then(Let([](auto& foo) { + >> Then(Let([](auto& foo) { return Then([&]() { foo.i += 1; }) - | Timer(std::chrono::milliseconds(1)) - | Then([&]() { + >> Timer(std::chrono::milliseconds(1)) + >> Then([&]() { return foo.i; }); })); diff --git a/test/lock.cc b/test/lock.cc index fe629b22..1662889b 100644 --- a/test/lock.cc +++ b/test/lock.cc @@ -32,8 +32,8 @@ TEST(LockTest, Succeed) { }); thread.detach(); }) - | Acquire(&lock) - | Then([](auto&& value) { return std::move(value); }); + >> Acquire(&lock) + >> Then([](auto&& value) { return std::move(value); }); }; auto e2 = [&]() { @@ -45,13 +45,13 @@ TEST(LockTest, Succeed) { }); thread.detach(); }) - | Acquire(&lock) - | Then([](auto&& value) { return std::move(value); }); + >> Acquire(&lock) + >> Then([](auto&& value) { return std::move(value); }); }; auto e3 = [&]() { return Release(&lock) - | Then([]() { return "t3"; }); + >> Then([]() { return "t3"; }); }; auto [future1, t1] = PromisifyForTest(e1()); @@ -77,22 +77,22 @@ TEST(LockTest, Fail) { auto e1 = [&]() { return Acquire(&lock) - | Eventual() - .raises() - .start([](auto& k) { - auto thread = std::thread( - [&k]() mutable { - k.Fail(std::runtime_error("error")); - }); - thread.detach(); - }) - | Release(&lock) - | Then([](auto&& value) { return std::move(value); }); + >> Eventual() + .raises() + .start([](auto& k) { + auto thread = std::thread( + [&k]() mutable { + k.Fail(std::runtime_error("error")); + }); + thread.detach(); + }) + >> Release(&lock) + >> Then([](auto&& value) { return std::move(value); }); }; auto e2 = [&]() { return Acquire(&lock) - | Then([]() { return "t2"; }); + >> Then([]() { return "t2"; }); }; EXPECT_THAT( @@ -114,21 +114,21 @@ TEST(LockTest, Stop) { auto e1 = [&]() { return Acquire(&lock) - | Eventual() - .interruptible() - .start([&](auto& k, auto& handler) { - CHECK(handler) << "Test expects interrupt to be registered"; - handler->Install([&k]() { - k.Stop(); - }); - start.Call(); - }) - | Release(&lock); + >> Eventual() + .interruptible() + .start([&](auto& k, auto& handler) { + CHECK(handler) << "Test expects interrupt to be registered"; + handler->Install([&k]() { + k.Stop(); + }); + start.Call(); + }) + >> Release(&lock); }; auto e2 = [&]() { return Acquire(&lock) - | Then([]() { return "t2"; }); + >> Then([]() { return "t2"; }); }; auto [future1, k1] = PromisifyForTest(e1()); @@ -157,20 +157,19 @@ TEST(LockTest, Wait) { .start([](auto& k) { k.Start("t1"); }) - | Acquire(&lock) - | Wait(&lock, - [&](auto notify) { - callback = std::move(notify); - return [waited = false](auto&& value) mutable { - if (!waited) { - waited = true; - return true; - } else { - return false; - } - }; - }) - | Release(&lock); + >> Acquire(&lock) + >> Wait(&lock, [&](auto notify) { + callback = std::move(notify); + return [waited = false](auto&& value) mutable { + if (!waited) { + waited = true; + return true; + } else { + return false; + } + }; + }) + >> Release(&lock); }; auto [future1, t1] = PromisifyForTest(e1()); @@ -206,7 +205,7 @@ TEST(LockTest, SynchronizableWait) { auto Operation() { return Synchronized( Just("operation") - | Wait([](auto notify) { + >> Wait([](auto notify) { return [](auto&&...) { return false; }; @@ -229,7 +228,7 @@ TEST(LockTest, SynchronizableThen) { Then([]() { return Just(42); })) - | Then([](auto i) { + >> Then([](auto i) { return i; }); } @@ -251,7 +250,7 @@ TEST(LockTest, OwnedByCurrentSchedulerContext) { } return Just(42); })) - | Then([this](auto i) { + >> Then([this](auto i) { if (lock().OwnedByCurrentSchedulerContext()) { ADD_FAILURE() << "lock should not be owned"; } @@ -270,10 +269,10 @@ TEST(LockTest, SynchronizedMap) { struct Foo : public Synchronizable { auto Operation() { return Iterate({1, 2}) - | Synchronized(Map([](int i) { + >> Synchronized(Map([](int i) { return ++i; })) - | Reduce( + >> Reduce( /* sum = */ 0, [](auto& sum) { return Then([&](auto i) { diff --git a/test/pipe.cc b/test/pipe.cc index 1297f1c5..1f2551ae 100644 --- a/test/pipe.cc +++ b/test/pipe.cc @@ -21,7 +21,7 @@ TEST(Pipe, UniqueValue) { auto e = [&pipe]() { return pipe.Read() - | Collect(); + >> Collect(); }; EXPECT_THAT(*e(), ElementsAre(1)); @@ -40,7 +40,7 @@ TEST(Pipe, Values) { auto e = [&pipe]() { return pipe.Read() - | Collect(); + >> Collect(); }; EXPECT_THAT(*e(), ElementsAre(1, 2, 3, 4, 5)); @@ -59,7 +59,7 @@ TEST(Pipe, Close) { auto e = [&pipe]() { return pipe.Read() - | Collect(); + >> Collect(); }; EXPECT_THAT(*e(), ElementsAre(1, 2)); @@ -75,7 +75,7 @@ TEST(Pipe, Size) { auto e = [&pipe]() { return pipe.Read() - | Collect(); + >> Collect(); }; EXPECT_EQ(*pipe.Size(), 2); diff --git a/test/poll.cc b/test/poll.cc index aa8c2a00..be8d8f8c 100644 --- a/test/poll.cc +++ b/test/poll.cc @@ -43,27 +43,28 @@ TEST_F(PollTest, Succeed) { auto e = [&]() { return DoAll( // Server: - Poll(server, PollEvents::Readable) | Reduce( - /* data = */ std::string(), - [&](auto& data) { - return Then([&](PollEvents events) { - EXPECT_EQ( - events & PollEvents::Readable, - PollEvents::Readable); - char buffer[1024]; - int size = recv(server, buffer, 1024, 0); - if (size > 0) { - data += std::string(buffer, size); - return /* continue = */ true; - } else { - // Reached EOF! - return /* continue = */ false; - } - }); - }), + Poll(server, PollEvents::Readable) + >> Reduce( + /* data = */ std::string(), + [&](auto& data) { + return Then([&](PollEvents events) { + EXPECT_EQ( + events & PollEvents::Readable, + PollEvents::Readable); + char buffer[1024]; + int size = recv(server, buffer, 1024, 0); + if (size > 0) { + data += std::string(buffer, size); + return /* continue = */ true; + } else { + // Reached EOF! + return /* continue = */ false; + } + }); + }), // Client: Poll(client, PollEvents::Writable) - | Map([&, first = true](PollEvents events) mutable { + >> Map([&, first = true](PollEvents events) mutable { if (first) { first = false; EXPECT_EQ(PollEvents::Writable, events); @@ -79,14 +80,14 @@ TEST_F(PollTest, Succeed) { return /* done = */ true; } }) - | Until([](bool done) { + >> Until([](bool done) { return done; }) - | Loop() - | Then([&]() { + >> Loop() + >> Then([&]() { Close(client); })) - | Then(Unpack([](std::string&& data, std::monostate) { + >> Then(Unpack([](std::string&& data, std::monostate) { return std::move(data); })); }; diff --git a/test/protobuf/collect.cc b/test/protobuf/collect.cc index 7cd90188..80634658 100644 --- a/test/protobuf/collect.cc +++ b/test/protobuf/collect.cc @@ -14,7 +14,7 @@ TEST(Collect, VectorToRepeatedPtrField) { auto s = [&]() { return Iterate(v) - | Collect(); + >> Collect(); }; google::protobuf::RepeatedPtrField result = *s(); @@ -42,7 +42,7 @@ TEST(Collect, MoveValueIntoRepeatedPtrField) { k.Ended(); } }) - | Collect(); + >> Collect(); }; google::protobuf::RepeatedPtrField result = *s(); @@ -59,7 +59,7 @@ TEST(Collect, VectorToRepeatedField) { auto s = [&]() { return Iterate(v) - | Collect(); + >> Collect(); }; google::protobuf::RepeatedField result = *s(); diff --git a/test/range.cc b/test/range.cc index 38743cd7..0a5e1f7f 100644 --- a/test/range.cc +++ b/test/range.cc @@ -14,77 +14,77 @@ using testing::ElementsAre; TEST(Range, CommonFlow) { auto s = Range(0, 5) - | Collect(); + >> Collect(); EXPECT_THAT(*s, ElementsAre(0, 1, 2, 3, 4)); } TEST(Range, IncorrectSetup) { auto s = Range(2, 0) - | Collect(); + >> Collect(); EXPECT_THAT(*s, ElementsAre()); } TEST(Range, NegativeRange) { auto s = Range(-2, 2) - | Collect(); + >> Collect(); EXPECT_THAT(*s, ElementsAre(-2, -1, 0, 1)); } TEST(Range, NegativeFrom) { auto s = Range(-2) - | Collect(); + >> Collect(); EXPECT_THAT(*s, ElementsAre()); } TEST(Range, DefaultFrom) { auto s = Range(3) - | Collect(); + >> Collect(); EXPECT_THAT(*s, ElementsAre(0, 1, 2)); } TEST(Range, SpecifiedStep) { auto s = Range(0, 10, 2) - | Collect(); + >> Collect(); EXPECT_THAT(*s, ElementsAre(0, 2, 4, 6, 8)); } TEST(Range, SpecifiedNegativeStep) { auto s = Range(10, 0, -2) - | Collect(); + >> Collect(); EXPECT_THAT(*s, ElementsAre(10, 8, 6, 4, 2)); } TEST(Range, SpecifiedStepIncorrect) { auto s = Range(10, 0, 2) - | Collect(); + >> Collect(); EXPECT_THAT(*s, ElementsAre()); } TEST(Range, SpecifiedStepIncorrectNegative) { auto s = Range(0, -10, 2) - | Collect(); + >> Collect(); EXPECT_THAT(*s, ElementsAre()); } TEST(Range, SpecifiedIncorrect) { auto s = Range(0, 10, -2) - | Collect(); + >> Collect(); EXPECT_THAT(*s, ElementsAre()); } TEST(Range, SpecifiedStepNegative) { auto s = Range(0, -10, -2) - | Collect(); + >> Collect(); EXPECT_THAT(*s, ElementsAre(0, -2, -4, -6, -8)); } diff --git a/test/repeat.cc b/test/repeat.cc index 875f953d..98f24a8f 100644 --- a/test/repeat.cc +++ b/test/repeat.cc @@ -28,13 +28,13 @@ TEST(RepeatTest, Succeed) { auto r = [&]() { return Repeat([i = 0]() mutable { return i++; }) - | Until([](auto& i) { + >> Until([](auto& i) { return i == 5; }) - | Map([&](auto&& i) { + >> Map([&](auto&& i) { return e(i); }) - | Reduce( + >> Reduce( /* sum = */ 0, [](auto& sum) { return Then([&](auto&& i) { @@ -59,13 +59,13 @@ TEST(RepeatTest, Fail) { auto r = [&]() { return Repeat([i = 0]() mutable { return i++; }) - | Until([](auto& i) { + >> Until([](auto& i) { return i == 5; }) - | Map([&](auto&& i) { + >> Map([&](auto&& i) { return e(i); }) - | Reduce( + >> Reduce( /* sum = */ 0, [](auto& sum) { return Then([&](auto&& i) { @@ -99,13 +99,13 @@ TEST(RepeatTest, Interrupt) { auto r = [&]() { return Repeat([i = 0]() mutable { return i++; }) - | Until([](auto& i) { + >> Until([](auto& i) { return i == 5; }) - | Map([&](auto&& i) { + >> Map([&](auto&& i) { return e(i); }) - | Reduce( + >> Reduce( /* sum = */ 0, [](auto& sum) { return Then([&](auto&& i) { @@ -135,25 +135,25 @@ TEST(RepeatTest, Interrupt) { TEST(RepeatTest, Map) { auto r = []() { return Repeat() - | Map([]() { + >> Map([]() { return Eventual() .start([](auto& k) { k.Start(1); }); }) - | Loop() - .context(0) - .body([](auto&& count, auto& repeated, auto&& value) { - count += value; - if (count >= 5) { - repeated.Done(); - } else { - repeated.Next(); - } - }) - .ended([](auto& count, auto& k) { - k.Start(std::move(count)); - }); + >> Loop() + .context(0) + .body([](auto&& count, auto& repeated, auto&& value) { + count += value; + if (count >= 5) { + repeated.Done(); + } else { + repeated.Next(); + } + }) + .ended([](auto& count, auto& k) { + k.Start(std::move(count)); + }); }; EXPECT_EQ(5, *r()); @@ -170,24 +170,24 @@ TEST(RepeatTest, MapAcquire) { k.Start(1); }); }) - | Acquire(&lock) - | Map([](auto&& i) { + >> Acquire(&lock) + >> Map([](auto&& i) { return i; }) - | Release(&lock) - | Loop() - .context(0) - .body([](auto&& count, auto& repeated, auto&& value) { - count += value; - if (count >= 5) { - repeated.Done(); - } else { - repeated.Next(); - } - }) - .ended([](auto& count, auto& k) { - k.Start(std::move(count)); - }); + >> Release(&lock) + >> Loop() + .context(0) + .body([](auto&& count, auto& repeated, auto&& value) { + count += value; + if (count >= 5) { + repeated.Done(); + } else { + repeated.Next(); + } + }) + .ended([](auto& count, auto& k) { + k.Start(std::move(count)); + }); }; EXPECT_EQ(5, *r()); diff --git a/test/signal.cc b/test/signal.cc index e0a76a99..92580bb5 100644 --- a/test/signal.cc +++ b/test/signal.cc @@ -29,7 +29,7 @@ class SignalTest : public EventLoopTest {}; TEST_F(SignalTest, SignalComposition) { auto e = WaitForSignal(SIGQUIT) - | Then([]() { + >> Then([]() { return "quit"; }); diff --git a/test/static-thread-pool.cc b/test/static-thread-pool.cc index c4bdb38f..60f64161 100644 --- a/test/static-thread-pool.cc +++ b/test/static-thread-pool.cc @@ -34,7 +34,7 @@ TEST(StaticThreadPoolTest, Schedulable) { Then([this]() { return i; })) - | Then([](auto i) { + >> Then([](auto i) { return i + 1; }); } @@ -66,11 +66,11 @@ TEST(StaticThreadPoolTest, Reschedulable) { }); thread.detach(); }) - | Eventual() - .start([&id](auto& k) { - EXPECT_EQ(id, std::this_thread::get_id()); - k.Start(); - }); + >> Eventual() + .start([&id](auto& k) { + EXPECT_EQ(id, std::this_thread::get_id()); + k.Start(); + }); })); }; @@ -85,12 +85,12 @@ TEST(StaticThreadPoolTest, PingPong) { auto Stream() { return Repeat() - | Until([this]() { + >> Until([this]() { return Schedule(Then([this]() { return count > 5; })); }) - | Schedule(Map([this]() mutable { + >> Schedule(Map([this]() mutable { return count++; })); } @@ -107,8 +107,8 @@ TEST(StaticThreadPoolTest, PingPong) { count++; return i; })) - | Loop() - | Then([this](auto&&...) { + >> Loop() + >> Then([this](auto&&...) { return count; }); } @@ -119,7 +119,7 @@ TEST(StaticThreadPoolTest, PingPong) { Streamer streamer(Pinned::ExactCPU(0)); Listener listener(Pinned::ExactCPU(1)); - EXPECT_EQ(6, *(streamer.Stream() | listener.Listen())); + EXPECT_EQ(6, *(streamer.Stream() >> listener.Listen())); } @@ -140,11 +140,11 @@ TEST(StaticThreadPoolTest, Spawn) { }); thread.detach(); }) - | Eventual() - .start([&id](auto& k) { - EXPECT_EQ(id, std::this_thread::get_id()); - k.Start(); - }); + >> Eventual() + .start([&id](auto& k) { + EXPECT_EQ(id, std::this_thread::get_id()); + k.Start(); + }); })); }; @@ -174,11 +174,11 @@ TEST(StaticThreadPoolTest, SpawnFail) { }); thread.detach(); }) - | Eventual() - .start([&id](auto& k) { - EXPECT_EQ(id, std::this_thread::get_id()); - k.Start(); - }); + >> Eventual() + .start([&id](auto& k) { + EXPECT_EQ(id, std::this_thread::get_id()); + k.Start(); + }); })); }; @@ -200,7 +200,7 @@ TEST(StaticThreadPoolTest, Concurrent) { "static thread pool", &requirements, Iterate({1, 2, 3}) - | Concurrent([&requirements]() { + >> Concurrent([&requirements]() { auto parent = Scheduler::Context::Get().reborrow(); EXPECT_EQ( parent->name(), @@ -217,7 +217,7 @@ TEST(StaticThreadPoolTest, Concurrent) { return i; }); }) - | Collect()); + >> Collect()); }; EXPECT_THAT(*e(), UnorderedElementsAre(1, 2, 3)); diff --git a/test/stream.cc b/test/stream.cc index 6ad2b9a3..50e1ff32 100644 --- a/test/stream.cc +++ b/test/stream.cc @@ -47,21 +47,21 @@ TEST(StreamTest, Succeed) { .done([&](auto&, auto&) { done.Call(); }) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }) - .fail([&](auto&, auto&, auto&&) { - fail.Call(); - }) - .stop([&](auto&, auto&) { - stop.Call(); - }); + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }) + .fail([&](auto&, auto&, auto&&) { + fail.Call(); + }) + .stop([&](auto&, auto&) { + stop.Call(); + }); }; EXPECT_EQ(15, *s()); @@ -87,24 +87,24 @@ TEST(StreamTest, Done) { .done([](auto&, auto& k) { k.Ended(); }) - | Loop() - .context(0) - .body([](auto& count, auto& stream, auto&&) { - if (++count == 2) { - stream.Done(); - } else { - stream.Next(); - } - }) - .ended([](auto& count, auto& k) { - k.Start(count); - }) - .fail([&](auto&, auto&, auto&&) { - fail.Call(); - }) - .stop([&](auto&, auto&) { - stop.Call(); - }); + >> Loop() + .context(0) + .body([](auto& count, auto& stream, auto&&) { + if (++count == 2) { + stream.Done(); + } else { + stream.Next(); + } + }) + .ended([](auto& count, auto& k) { + k.Start(count); + }) + .fail([&](auto&, auto&, auto&&) { + fail.Call(); + }) + .stop([&](auto&, auto&) { + stop.Call(); + }); }; EXPECT_EQ(2, *s()); @@ -137,21 +137,21 @@ TEST(StreamTest, Fail) { .done([&](auto&, auto&) { done.Call(); }) - | Loop() - .context(0) - .raises() - .body([](auto&, auto& stream, auto&&) { - stream.Next(); - }) - .ended([&](auto&, auto&) { - ended.Call(); - }) - .fail([&](auto&, auto& k, auto&& error) { - k.Fail(std::forward(error)); - }) - .stop([&](auto&, auto&) { - stop.Call(); - }); + >> Loop() + .context(0) + .raises() + .body([](auto&, auto& stream, auto&&) { + stream.Next(); + }) + .ended([&](auto&, auto&) { + ended.Call(); + }) + .fail([&](auto&, auto& k, auto&& error) { + k.Fail(std::forward(error)); + }) + .stop([&](auto&, auto&) { + stop.Call(); + }); }; static_assert( @@ -203,26 +203,26 @@ TEST(StreamTest, InterruptStream) { .done([&](auto&, auto&, auto&) { done.Call(); }) - | Loop() - .body([&](auto& k, auto&&) { - auto thread = std::thread( - [&]() mutable { - while (!triggered.load()) { - std::this_thread::yield(); - } - k.Next(); - }); - thread.detach(); - }) - .ended([&](auto&) { - ended.Call(); - }) - .fail([&](auto&, auto&&) { - fail.Call(); - }) - .stop([](auto& k) { - k.Stop(); - }); + >> Loop() + .body([&](auto& k, auto&&) { + auto thread = std::thread( + [&]() mutable { + while (!triggered.load()) { + std::this_thread::yield(); + } + k.Next(); + }); + thread.detach(); + }) + .ended([&](auto&) { + ended.Call(); + }) + .fail([&](auto&, auto&&) { + fail.Call(); + }) + .stop([](auto& k) { + k.Stop(); + }); }; auto [future, k] = PromisifyForTest(s()); @@ -261,42 +261,42 @@ TEST(StreamTest, InterruptLoop) { .done([](auto& k) { k.Ended(); }) - | Loop() - .context(Lazy>(false)) - .interruptible() - .raises() - .begin([](auto& interrupted, - auto& k, - auto& handler) { - CHECK(handler) << "Test expects interrupt to be registered"; - handler->Install([&interrupted]() { - interrupted->store(true); - }); - k.Next(); - }) - .body([&](auto&, auto& k, auto&, auto&&) { - auto thread = std::thread( - [&]() mutable { - while (!triggered.load()) { - std::this_thread::yield(); - } - k.Done(); - }); - thread.detach(); - }) - .ended([](auto& interrupted, auto& k, auto&) { - if (interrupted->load()) { - k.Stop(); - } else { - k.Fail(std::runtime_error("error")); - } - }) - .fail([&](auto&, auto&, auto&&) { - fail.Call(); - }) - .stop([&](auto&, auto&) { - stop.Call(); - }); + >> Loop() + .context(Lazy>(false)) + .interruptible() + .raises() + .begin([](auto& interrupted, + auto& k, + auto& handler) { + CHECK(handler) << "Test expects interrupt to be registered"; + handler->Install([&interrupted]() { + interrupted->store(true); + }); + k.Next(); + }) + .body([&](auto&, auto& k, auto&, auto&&) { + auto thread = std::thread( + [&]() mutable { + while (!triggered.load()) { + std::this_thread::yield(); + } + k.Done(); + }); + thread.detach(); + }) + .ended([](auto& interrupted, auto& k, auto&) { + if (interrupted->load()) { + k.Stop(); + } else { + k.Fail(std::runtime_error("error")); + } + }) + .fail([&](auto&, auto&, auto&&) { + fail.Call(); + }) + .stop([&](auto&, auto&) { + stop.Call(); + }); }; static_assert( @@ -331,8 +331,8 @@ TEST(StreamTest, InfiniteLoop) { k.Ended(); } }) - | Map([](int i) { return i + 1; }) - | Loop(); + >> Map([](int i) { return i + 1; }) + >> Loop(); }; *s(); @@ -350,16 +350,16 @@ TEST(StreamTest, MapThenLoop) { k.Ended(); } }) - | Map([](int i) { return i + 1; }) - | Loop() - .context(0) - .body([](auto& sum, auto& stream, auto&& value) { - sum += value; - stream.Next(); - }) - .ended([](auto& sum, auto& k) { - k.Start(sum); - }); + >> Map([](int i) { return i + 1; }) + >> Loop() + .context(0) + .body([](auto& sum, auto& stream, auto&& value) { + sum += value; + stream.Next(); + }) + .ended([](auto& sum, auto& k) { + k.Start(sum); + }); }; EXPECT_EQ(20, *s()); @@ -380,10 +380,10 @@ TEST(StreamTest, MapThenReduce) { .done([](auto&, auto& k) { k.Ended(); }) - | Map([](int i) { + >> Map([](int i) { return i + 1; }) - | Reduce( + >> Reduce( /* sum = */ 0, [](auto& sum) { return Then([&](auto&& value) { @@ -403,7 +403,7 @@ TEST(StreamTest, Head) { .next([](auto& k) { k.Emit(42); }) - | Head(); + >> Head(); }; EXPECT_EQ(42, *s1()); @@ -413,7 +413,7 @@ TEST(StreamTest, Head) { .next([](auto& k) { k.Ended(); }) - | Head(); + >> Head(); }; EXPECT_THAT( @@ -424,11 +424,11 @@ TEST(StreamTest, Head) { TEST(StreamTest, PropagateError) { auto e = []() { return Raise(std::runtime_error("error")) - | Stream() - .next([](auto& k) { - k.Ended(); - }) - | Head(); + >> Stream() + .next([](auto& k) { + k.Ended(); + }) + >> Head(); }; static_assert( @@ -444,20 +444,20 @@ TEST(StreamTest, PropagateError) { TEST(StreamTest, ThrowSpecificError) { auto e = []() { return Raise(std::bad_alloc()) - | Stream() - .raises() - .fail([](auto& k, auto&& error) { - static_assert( - std::is_same_v< - std::decay_t, - std::bad_alloc>); - - k.Fail(std::runtime_error("error")); - }) - .next([](auto& k) { - k.Ended(); - }) - | Head(); + >> Stream() + .raises() + .fail([](auto& k, auto&& error) { + static_assert( + std::is_same_v< + std::decay_t, + std::bad_alloc>); + + k.Fail(std::runtime_error("error")); + }) + .next([](auto& k) { + k.Ended(); + }) + >> Head(); }; static_assert( @@ -473,20 +473,20 @@ TEST(StreamTest, ThrowSpecificError) { TEST(StreamTest, ThrowGeneralError) { auto e = []() { return Raise(std::bad_alloc()) - | Stream() - .raises() // Same as 'raises'. - .fail([](auto& k, auto&& error) { - static_assert( - std::is_same_v< - std::decay_t, - std::bad_alloc>); - - k.Fail(std::runtime_error("error")); - }) - .next([](auto& k) { - k.Ended(); - }) - | Head(); + >> Stream() + .raises() // Same as 'raises'. + .fail([](auto& k, auto&& error) { + static_assert( + std::is_same_v< + std::decay_t, + std::bad_alloc>); + + k.Fail(std::runtime_error("error")); + }) + .next([](auto& k) { + k.Ended(); + }) + >> Head(); }; static_assert( diff --git a/test/take.cc b/test/take.cc index 23418aa8..24500a05 100644 --- a/test/take.cc +++ b/test/take.cc @@ -19,8 +19,8 @@ TEST(Take, IterateTakeLastCollect) { auto s = [&]() { return Iterate(v) - | TakeLast(2) - | Collect(); + >> TakeLast(2) + >> Collect(); }; EXPECT_THAT(*s(), ElementsAre(17, 3)); @@ -31,8 +31,8 @@ TEST(Take, IterateTakeLastAllCollect) { auto s = [&]() { return Iterate(v) - | TakeLast(4) - | Collect(); + >> TakeLast(4) + >> Collect(); }; EXPECT_THAT(*s(), ElementsAre(5, 12, 17, 3)); @@ -43,8 +43,8 @@ TEST(Take, IterateTakeRangeCollect) { auto s = [&]() { return Iterate(v) - | TakeRange(1, 2) - | Collect(); + >> TakeRange(1, 2) + >> Collect(); }; EXPECT_THAT(*s(), ElementsAre(12, 17)); @@ -55,9 +55,9 @@ TEST(Take, IterateTakeRangeFilterCollect) { auto s = [&]() { return Iterate(v) - | TakeRange(1, 2) - | Filter([](int x) { return x % 2 == 0; }) - | Collect(); + >> TakeRange(1, 2) + >> Filter([](int x) { return x % 2 == 0; }) + >> Collect(); }; EXPECT_THAT(*s(), ElementsAre(12)); @@ -68,8 +68,8 @@ TEST(Take, IterateTakeFirstCollect) { auto s = [&]() { return Iterate(v) - | TakeFirst(3) - | Collect(); + >> TakeFirst(3) + >> Collect(); }; EXPECT_THAT(*s(), ElementsAre(5, 12, 17)); @@ -81,9 +81,9 @@ TEST(Take, IterateTakeFirstFilterCollect) { auto s = [&]() { return Iterate(v) - | TakeFirst(3) - | Filter([](int x) { return x % 2 == 1; }) - | Collect(); + >> TakeFirst(3) + >> Filter([](int x) { return x % 2 == 1; }) + >> Collect(); }; EXPECT_THAT(*s(), ElementsAre(5, 17)); @@ -94,8 +94,8 @@ TEST(Take, TakeLastOutOfRange) { auto s = [&]() { return Iterate(v) - | TakeLast(100) - | Collect(); + >> TakeLast(100) + >> Collect(); }; EXPECT_THAT(*s(), ElementsAre(5, 12, 17, 3)); @@ -106,8 +106,8 @@ TEST(Take, TakeFirstOutOfRange) { auto s = [&]() { return Iterate(v) - | TakeFirst(100) - | Collect(); + >> TakeFirst(100) + >> Collect(); }; EXPECT_THAT(*s(), ElementsAre(5, 12, 17, 3)); @@ -118,8 +118,8 @@ TEST(Take, TakeRangeStartOutOfRange) { auto s = [&]() { return Iterate(v) - | TakeRange(100, 100) - | Collect(); + >> TakeRange(100, 100) + >> Collect(); }; EXPECT_THAT(*s(), ElementsAre()); @@ -130,8 +130,8 @@ TEST(Take, TakeRangeAmountOutOfRange) { auto s = [&]() { return Iterate(v) - | TakeRange(1, 100) - | Collect(); + >> TakeRange(1, 100) + >> Collect(); }; EXPECT_THAT(*s(), ElementsAre("12", "17", "3")); @@ -145,8 +145,8 @@ TEST(Take, UniquePtr) { auto s = [&]() { return Iterate(std::move(v)) - | TakeRange(0, 100) - | Collect(); + >> TakeRange(0, 100) + >> Collect(); }; auto result = *s(); @@ -167,8 +167,8 @@ TEST(Take, TakeRangeInfiniteStream) { k.Emit(i++); } }) - | TakeRange(0, 2) - | Collect(); + >> TakeRange(0, 2) + >> Collect(); }; EXPECT_THAT(*s(), ElementsAre(0, 1)); diff --git a/test/task.cc b/test/task.cc index f46ecd82..9a080d34 100644 --- a/test/task.cc +++ b/test/task.cc @@ -30,10 +30,10 @@ TEST(Task, Succeed) { auto e2 = [&]() { return e1() - | Then([](int i) { + >> Then([](int i) { return i + 1; }) - | e1(); + >> e1(); }; EXPECT_EQ(42, *e2()); @@ -52,10 +52,10 @@ TEST(Task, Succeed) { auto e4 = [&]() { return e3() - | Then([](int i) { + >> Then([](int i) { return i + 1; }) - | e3(); + >> e3(); }; EXPECT_EQ(42, *e4()); @@ -142,19 +142,19 @@ TEST(Task, FailOnCallback) { functions.fail.Call(); k.Fail(std::runtime_error("error from fail")); }) - | Then([](int) { return 1; }) - | Eventual() - .start([&](auto& k, auto&& value) { - functions.start.Call(); - }) - .stop([&](auto&) { - functions.stop.Call(); - }) - .fail([&](auto& k, auto&& error) { - functions.fail.Call(); - k.Fail(eventuals::make_exception_ptr_or_forward( - std::forward(error))); - }); + >> Then([](int) { return 1; }) + >> Eventual() + .start([&](auto& k, auto&& value) { + functions.start.Call(); + }) + .stop([&](auto&) { + functions.stop.Call(); + }) + .fail([&](auto& k, auto&& error) { + functions.fail.Call(); + k.Fail(eventuals::make_exception_ptr_or_forward( + std::forward(error))); + }); }; }; @@ -185,7 +185,7 @@ TEST(Task, FailTerminated) { fail.Call(); k.Fail(std::runtime_error("error from fail")); }) - | Then([](int x) { return x + 1; }); + >> Then([](int x) { return x + 1; }); }; }; @@ -393,8 +393,8 @@ TEST(Task, FromTo) { auto e = [&]() { return Just(10) - | task() - | Then([](std::string&& s) { + >> task() + >> Then([](std::string&& s) { s += "1"; return std::move(s); }); @@ -418,9 +418,9 @@ TEST(Task, FromToFail) { .start([](auto& k) { k.Fail(std::runtime_error("error")); }) - | Just(10) - | task() - | Then([](std::string&& s) { + >> Just(10) + >> task() + >> Then([](std::string&& s) { s += "1"; return std::move(s); }); @@ -450,9 +450,9 @@ TEST(Task, FromToStop) { .start([](auto& k) { k.Stop(); }) - | Just(10) - | task() - | Then([](std::string&& s) { + >> Just(10) + >> task() + >> Then([](std::string&& s) { s += "1"; return std::move(s); }); @@ -472,7 +472,7 @@ TEST(Task, Success) { auto e = [&]() { return f() - | g(); + >> g(); }; EXPECT_EQ("hello", *e()); @@ -526,17 +526,17 @@ TEST(Task, Inheritance) { auto sync = [&]() { return f() - | Sync().GetTask(); + >> Sync().GetTask(); }; auto async = [&]() { return f() - | Async().GetTask(); + >> Async().GetTask(); }; auto failure = [&]() { return f() - | Failure().GetTask(); + >> Failure().GetTask(); }; static_assert( @@ -578,7 +578,7 @@ TEST(Task, ConstRefSuccess) { auto e1 = [&]() { return e() - | Then([](const int& value) { + >> Then([](const int& value) { return value + 10; }); }; @@ -620,7 +620,7 @@ TEST(Task, RefFunction) { auto e1 = [&]() { return e() - | Then([](auto& v) { + >> Then([](auto& v) { v += 100; }); }; @@ -638,7 +638,7 @@ TEST(Task, RefSuccess) { auto e1 = [&]() { return e() - | Then([](auto& v) { + >> Then([](auto& v) { v += 100; }); }; diff --git a/test/then.cc b/test/then.cc index f9f236cd..3a7e9eac 100644 --- a/test/then.cc +++ b/test/then.cc @@ -33,8 +33,8 @@ TEST(ThenTest, Succeed) { }); thread.detach(); }) - | Then([](int i) { return i + 1; }) - | Then([&](auto&& i) { + >> Then([](int i) { return i + 1; }) + >> Then([&](auto&& i) { return e("then"); }); }; @@ -46,7 +46,7 @@ TEST(ThenTest, SucceedVoid) { bool ran = false; auto e = [&]() { return Just() - | Then([&]() { + >> Then([&]() { ran = true; }); }; @@ -77,8 +77,8 @@ TEST(ThenTest, Fail) { }); thread.detach(); }) - | Then([](int i) { return i + 1; }) - | Then([&](auto&& i) { + >> Then([](int i) { return i + 1; }) + >> Then([&](auto&& i) { return e("then"); }); }; @@ -110,8 +110,8 @@ TEST(ThenTest, Interrupt) { .start([](auto& k) { k.Start(0); }) - | Then([](int i) { return i + 1; }) - | Then([&](auto&& i) { + >> Then([](int i) { return i + 1; }) + >> Then([&](auto&& i) { return e("then"); }); }; diff --git a/test/timer.cc b/test/timer.cc index 047a2f4d..3d2c5cb6 100644 --- a/test/timer.cc +++ b/test/timer.cc @@ -36,7 +36,7 @@ TEST_F(EventLoopTest, PauseAndAdvanceClock) { auto e = []() { return Timer(std::chrono::seconds(5)) - | Just(42); + >> Just(42); }; auto [future, k] = PromisifyForTest(e()); @@ -151,7 +151,7 @@ TEST_F(EventLoopTest, PauseClockInterruptTimer) { TEST_F(EventLoopTest, TimerAfterTimer) { auto e = []() { return Timer(std::chrono::milliseconds(5)) - | Timer(std::chrono::milliseconds(5)); + >> Timer(std::chrono::milliseconds(5)); }; auto [future, k] = PromisifyForTest(e()); diff --git a/test/transformer.cc b/test/transformer.cc index 2498c560..4c11e134 100644 --- a/test/transformer.cc +++ b/test/transformer.cc @@ -33,11 +33,11 @@ TEST(Transformer, Succeed) { auto e = [&]() { return Iterate({100}) - | transformer() - | Map([](std::string s) { + >> transformer() + >> Map([](std::string s) { return s; }) - | Collect(); + >> Collect(); }; EXPECT_THAT(*e(), ElementsAre("100")); @@ -64,12 +64,12 @@ TEST(Transformer, Stop) { .next([](auto& k) { k.Stop(); }) - | transformer() - | Map([&](std::string s) { + >> transformer() + >> Map([&](std::string s) { map_start.Call(); return s; }) - | Collect(); + >> Collect(); }; EXPECT_THROW(*e(), eventuals::StoppedException); @@ -97,12 +97,12 @@ TEST(Transformer, Fail) { .next([](auto& k) { k.Fail(std::runtime_error("error")); }) - | transformer() - | Map([&](std::string s) { + >> transformer() + >> Map([&](std::string s) { map_start.Call(); return s; }) - | Collect(); + >> Collect(); }; static_assert( @@ -153,12 +153,12 @@ TEST(Transformer, Interrupt) { .done([&](auto&, auto&) { done.Call(); }) - | transformer() - | Map([&](std::string s) { + >> transformer() + >> Map([&](std::string s) { map_start.Call(); return s; }) - | Collect(); + >> Collect(); }; Interrupt interrupt; @@ -192,12 +192,12 @@ TEST(Transformer, PropagateStop) { auto e = [&]() { return Iterate({100}) - | transformer() - | Map([&](std::string s) { + >> transformer() + >> Map([&](std::string s) { map_start.Call(); return s; }) - | Collect(); + >> Collect(); }; EXPECT_THROW(*e(), eventuals::StoppedException); @@ -224,12 +224,12 @@ TEST(Transformer, PropagateFail) { auto e = [&]() { return Iterate({100}) - | transformer() - | Map([&](std::string s) { + >> transformer() + >> Map([&](std::string s) { map_start.Call(); return s; }) - | Collect(); + >> Collect(); }; static_assert( diff --git a/test/type-check.cc b/test/type-check.cc index 5ecffb7a..33802029 100644 --- a/test/type-check.cc +++ b/test/type-check.cc @@ -15,7 +15,7 @@ TEST(TypeCheck, Lvalue) { auto s = [&]() { return TypeCheck(Iterate(v)) - | Collect(); + >> Collect(); }; EXPECT_EQ(v, *s()); @@ -25,7 +25,7 @@ TEST(TypeCheck, Lvalue) { TEST(TypeCheck, Rvalue) { auto s = []() { return TypeCheck(Iterate(std::vector({5, 12}))) - | Collect(); + >> Collect(); }; EXPECT_EQ(std::vector({5, 12}), *s()); diff --git a/test/unpack.cc b/test/unpack.cc index 71b587a5..89e9b2ec 100644 --- a/test/unpack.cc +++ b/test/unpack.cc @@ -13,7 +13,7 @@ namespace { TEST(Unpack, Unpack) { auto e = []() { return Just(std::tuple{4, "2"}) - | Then(Unpack([](int i, std::string&& s) { + >> Then(Unpack([](int i, std::string&& s) { return std::to_string(i) + s; })); };