So I have recently had a situation where i had an iterator over String, and I wanted to join them with a space in the middle. it turned out to be really awkward.
I was surprised to be unable to find a join method on the iterator that did the job.
I did find std::slice::SliceConcatExt But that seems to be rather specific on slices, and I didn’t want to make one.
Rather than solve the problem for my specific case, I remembered that Premature Generalization is the root of all Evil, and so of course that’s what I did.
The above is a joining iterator trait called Joinable which works on almost anything. It clones and repeats the joining parameyer and alternates with the original iterator starting and ending with values from the original iterator.
Could this / or something like it have a place in the stdlib?
yeah, I pondered writing using some actual form of interleave on two separate iterators and then making this a specific case,where the iterator returns the same thing.
I think that might have been too generalized even for me.