Skip to content
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

[FEATURE] support kumi::map without a return type #3

Closed
ldalessa opened this issue Nov 14, 2021 · 5 comments
Closed

[FEATURE] support kumi::map without a return type #3

ldalessa opened this issue Nov 14, 2021 · 5 comments
Labels
enhancement New feature or request

Comments

@ldalessa
Copy link

Is your feature request related to a problem? Please describe.
When I have tuples of references it makes sense to map them without returning anything. Currently providing an invocable that returns void results in a compilation error.

Describe the solution you'd like
Specialize on the return type of the function object, if void then don't try and produce a tuple.

Describe alternatives you've considered
The current workaround is to return something trivial, like 0.

Additional context
https://godbolt.org/z/b56T3ebjd

@jfalcou
Copy link
Owner

jfalcou commented Nov 14, 2021

map is basically transform. I think you want to call for_each : https://godbolt.org/z/vz9Gqdavr

@ldalessa
Copy link
Author

In this case I have a zip-like thing happening and really do want map-like functionality.

std::vector<int> a, b, c, d;
kumi::tuple l = { std::ref(a), std::ref(b) };
kumi::tuple r = {std::ref(c), std::ref(d) };
kumi::map([](auto&& l, auto&& r) {
    return l[0] = r[0]; // don't want to return
}, l, r);

@jfalcou jfalcou transferred this issue from another repository Nov 27, 2021
@ldalessa
Copy link
Author

ldalessa commented Dec 4, 2021

It's possible that this should just be a separate function named zip_with.

@jfalcou jfalcou added the enhancement New feature or request label Dec 28, 2021
@DenisYaroshevskiy
Copy link

I fail to see how

kumi::map([](auto&& l, auto&& r) {
    return l[0] = r[0]; // don't want to return
    }, l, r);

is not:

kumi::for_each([](auto&& l, auto&& r) {
   l[0] = r[0];
 }, l, r);

Is that you want it to be called map? I mean, it's not rly map.

@ldalessa
Copy link
Author

ldalessa commented Jan 16, 2022

If for_each supports zipping then that’s what I want. I don’t want map, that was my original complaint.

I’m unfamiliar with the use of algorithms called for_each that provide this zip functionality. I think it’s more traditionally called zip_with. Now I know what kumi calls it is though, I’m happy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants