-
Notifications
You must be signed in to change notification settings - Fork 319
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: n-dimensional product over the same iterator #264
Comments
Is this so common as to warrant an |
Ah that's a nice solution, thanks! The Having this feature in the fn truth_table(dim: usize) → Box<Iterator<Item = Vec<bool>>> {
Box::new(iter::repeat(vec![false, true]).take(dim).multi_cartesian_product()
} |
I wince a bit at all of this, since any product / flat_map or other "nested loop" iterator will have performance or code gen problems in Rust. But if that is not of primary concern, then it's ok. Demo of the difference is in #222 (comment) (where you can see that fold/for_each, representing internal iteration, don't have to have the problem.) |
I don't mind adding that syntax to the macro, with the caveats that it has to be feasible to implement and that one thinks over what the duplicate syntax/ownership/cloning semantic is for the repetition. |
Maybe I should throw in something really ridiculous and then we can think of what it should result in: let mut i = 0;
iproduct!( { i += 1; i..10 }; 3); Note that this might not be so ridiculous, the |
I would like to volunteer myself for adding this syntax if work hasn't already started. I haven't done any macro work; this seems like a nice place to start. |
Is there any progress on that? |
I want this feature because |
This would be a nice and convenient addition. First, the "repeat parameter" is given literally like
Clone would not be needed by bluss example but is mandatory for simpler The question is when to evalute the expression, once or I think we should choose and document this behavior. And I don't know what's blocking this feature except this choice. Anyway, both cases relies on We currently can't do Both full new patterns (click to expand)
Because the first pattern allows more, I would choose it. I don't see how the macro could be made shorter, maybe you do, but I don't see why it would be a problem. |
So that code like this:
becomes the more succinct:
This would mandate vectors instead of tuples for the items.
It would help for when the dimension isn't known until runtime:
The text was updated successfully, but these errors were encountered: