-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
lager::with() and lager::reader<tuple<...>> behave in a non-symmetrical way #172
Comments
They are not meant to be symmetric. |
Hi, @arximboldi! The problem is not that reader<std::string> converted_from_tuple{tuplified.xform(zug::unzip).map(callback)}; In the real code here we use It is also impossible to bind to a PS: namespace kismpl {
/**
* Convert a given functor f accepting multiple arguments into
* a function that accepts a tuple with the same number of
* elements
*/
constexpr auto unzip_wrapper = [] (auto f) {
return
[=] (auto &&x) {
return std::apply(f, std::forward<decltype(x)>(x));
};
};
}
TEST_CASE("tuple unfolding when binding")
{
auto callback = [] ([[maybe_unused]] int x, [[maybe_unused]] std::string y) {
std::cout << "unpacked callback" << std::endl;
};
auto callback_tuple = [] ([[maybe_unused]] std::tuple<int, std::string> x) {
std::cout << "packed callback" << std::endl;
};
state<int, automatic_tag> value1{7};
state<std::string, automatic_tag> value2{"value"};
reader<std::tuple<int, std::string>> converted_value{with(value1, value2)};
converted_value.bind(kismpl::unzip_wrapper(callback));
converted_value.bind(callback_tuple);
}
Is it possible to implement the same with the standard transducers? Or, perhaps, we could include this wrapper into lager? |
Hmmm, interesting, something like this should work: auto callback = [](int x, string y) { return y; };
reader<tuple<int, string>> tuplified = ...;
reader<std::string> converted_from_tuple{tuplified.xform(zug::unzip).map(callback)}; In what way does this fail? |
Here is the full error message: https://invent.kde.org/-/snippets/2458 The line at reader<std::string> converted_from_tuple{tuplified.xform(zug::unzip).map(callback)}; (from the branch linked above) |
Hmm interesting, that looks indeed like a bug! |
Maybe the bug is in |
There is a unittest in this branch: ba8fe64 Or you mean a unittest for zug? |
Hmmm, after some thought, maybe the bug is not in |
I have a feeling like there is some bug in mapping readers holding a tuple. It seems to be impossible to map-unzip them into a normal function. Here is a code example:
It is possible to map a
with
-expression to both, tuple-style and unfolded callback, but it is impossible to map a tuple-containing reader to it.Full unittest is in this commit: ba8fe64
The text was updated successfully, but these errors were encountered: