-
Notifications
You must be signed in to change notification settings - Fork 315
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
Add Itertools::intersperse_with #381
Conversation
I came here to write exactly this. I planned to:
|
I second this suggestion. We do it in other places, too, and my most recent tests indicate that the compiler is actually smart enough to inline things properly (at least with As a side note: Is possibly even |
It may not actually be possible to implement
Basically the same underlying issue as why #377 can't just return with a new closure - requiring |
Actually the issue is not just
I'm not sure why that would be problematic if not invoked from the inherent methods, but it seems that it is.
It's interesting that the method can accept |
This looks good to me. Could you resolve the merge conflict? |
7985ca4
to
d55f0fb
Compare
3f0962f
to
22b1984
Compare
Thanks! bors r+ |
Build succeeded: |
Pretty self-explanatory. Useful for non-clonable elements or otherwise stateful interspersing.
intersperse()
could be implemented viaintersperse_with()
, allowing the change to be more minimal. I haven't done it currently, but if you don't see any downsides I'd amend this change to doself.intersperse_with(|| element)
forintersperse()
instead.