profile
viewpoint

Ask questionsTracking Issue for `Iterator::intersperse`

<!-- Thank you for creating a tracking issue! 📜 Tracking issues are for tracking a feature from implementation to stabilisation. Make sure to include the relevant RFC for the feature if it has one. Otherwise provide a short summary of the feature and link any relevant PRs or issues, and remove any sections that are not relevant to the feature.

Remember to add team labels to the tracking issue. For a language team feature, this would e.g., be T-lang. Such a feature should also be labeled with e.g., F-my_feature. This label is used to associate issues (e.g., bugs and design questions) to the feature. -->

This is a tracking issue for the Iterator::intersperse method. It is based on itertools::intersperse and is the iterator equivalent of Vec::join. The feature gate for the issue is #![feature(iter_intersperse)].

About tracking issues

Tracking issues are used to record the overall progress of implementation. They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions. A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature. Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.

Steps

<!-- Include each step required to complete the feature. Typically this is a PR implementing a feature, followed by a PR that stabilises the feature. However for larger features an implementation could be broken up into multiple PRs. -->

  • [x] Implement the feature (done in #79479)
  • [ ] Add impl<I: FusedIterator> FusedIterator for Intersperse<I>? (Can be added after stabilization, so not urgent.)
  • [ ] Stabilization PR

Unresolved Questions

<!-- Include any open questions that need to be answered before the feature can be stabilised. -->

None.

Implementation history

<!-- Include a list of all the PRs that were involved in implementing the feature. -->

  • Implemented Iterator::intersperse in #79479
rust-lang/rust

Answer questions kaylynn234

why not use join and join_with for iterators too?

I feel like join implies the creation of something monolithic from a sequence and a separator, i.e

let items = vec!["foo", "bar", "blah"];
let result = items.join(" ");

will create the string foo bar blah, and I don't have any issue with that.

But in my mind intersperse better communicates the idea of placing separators in between a sequence, without creating something monolithic using the results of that.

I suppose I mean that if I intersperse an iterator of &strs with " ", it makes sense to me that I get an iterator back. But if I have an iterator of &strs, and the method is named join, I feel like it's a little less clear. Without looking further into it, it might seem like that I'd get a concatenated String back, or similar. For other types it may be less unclear but I'm still unsure on whether calling the method join is a good fit.

useful!
source:https://uonfu.com/
Github User Rank List