rust-itertools / itertools

Extra iterator adaptors, iterator methods, free functions, and macros.
https://docs.rs/itertools/
Apache License 2.0
2.69k stars 303 forks source link

`iproduct`: generate tuples for simpler cases too #870

Closed Philippe-Cholet closed 7 months ago

Philippe-Cholet commented 7 months ago

Fixes #868 Allow trailing commas is convenient when the macro is on multiple lines.

Fixes #869 It is more consistent to return tuples in every case. It however is a breaking change. Note the new case: the empty product generating a single unit tuple (), similar to the recent #835.

What do you think? EDIT: 2nd option, we can fix the first one and close the second.

PS: I note that semver-checks does not see much breaking changes lately.

codecov[bot] commented 7 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (1f69c53) 94.20% compared to head (5ab11d6) 94.08%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #870 +/- ## ========================================== - Coverage 94.20% 94.08% -0.12% ========================================== Files 48 48 Lines 6676 6676 ========================================== - Hits 6289 6281 -8 - Misses 387 395 +8 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

Philippe-Cholet commented 7 months ago

I just added some simple tests.

my gut feeling is that the Macro has a bit many branches, but I think we can clean that up later if we want to

It would have even more branches if we ever do #264

(Similarly, for izip, there is #267.)

ijackson commented 7 months ago

(T,) is a somewhat exotic type

Indeed. But iproduct!( just_one_iterator ) is weird too. In practice people won't write such code by hand very often. Even when they do (eg when messing about trying to decide between code patterns, or commenting bits out, or something) providing the unary tuple will probably be more convenient as it'll involve less editing of the code that handles the output elements.

Given this, I'm okay with approving this PR.

Thanks.