-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
element-wise transform on mux'd pipes #36
Comments
@tnovotny
So - this would work - define the operator std::ostream& operator << (std::ostream& os, std::tuple<int, int> const& t) {
return os << "(" << std::get<0>(t) << "," << std::get<1>(t) << ")";
} and the following code should work then TEST_CASE("streamed filtered mux")
{
std::vector<int> a{ 1, 2, 3, 4 };
std::vector<int> b{ 11, 22, 33, 44 };
auto resultStream = std::ostringstream{};
std::string expected = "(20,17)(30,28)(40,39)";
pipes::mux(a, b)
>>= pipes::transform([](auto i, auto j) { return std::make_tuple(i * 10, j - 5); })
>>= pipes::filter([](auto const& t) -> bool { return std::get<0>(t) + std::get<1>(t) > 30.0; })
>>= pipes::to_out_stream(resultStream);
auto const results = resultStream.str();
REQUIRE(results == expected);
} |
Yes, that works, but not the way that I would like it to work. My code example did not compile, but the change I wanted was to make it compile without changing my code. See non exhaustive pipes
|
@tnovotny |
OK, you are right, maybe that answer didn't clear things up as much as I had hoped, and after some rethinking, there is the issue of what
and produces the output
|
@tnovotny The thing is - and I think that is a special case in your example - that Maybe the pipes library could add a type (derived from tuple) that is automatically unpacked to the next pipe when returned? I think that might be more difficult to implement with C++-14 (which pipes is implemented in) and rather easy in C++-17 or later. But that might be a good solution because then the output - or rather the input for the next pipe - would be well defined. maybe call it pipes::pack? pipes::tuple? std::vector<int> a{ 1, 2, 3, 4 };
std::vector<int> b{ 11, 22, 33, 44 };
mux( a, b ) >>=transform( []( auto i, auto j ) {
return pipes::pack{ i * 10, j - 5 };
} )
>>= filter( []( auto i, auto j ) { return i + j > 30.0; } )
>>= print{}; btw that would be a general solution and independent from |
It would be nice if element-wise transformations like this worked on mux'd streams.
Since this does something different than passing on the returned value, it might be desirable to make a new/different pipe and to keep the existing behavior under the existing name.
The text was updated successfully, but these errors were encountered: