Open camelid opened 3 years ago
@workingjubilee my disagreement with wording like insert_between
is that it sounds very imperative, whereas Iterator
methods (almost) always have declarative wording in line with their behavior.
I think separate_with
fits better than insert_between
with the grammatical pattern of existing iterator methods. Maybe other people turn the method names into sentences differently, but here's what my brain does:
method | mental expansion |
---|---|
verb_adverb |
verb "items" adverb (argument) |
step_by |
step (over) items by |
take_while |
take items while |
collect_into |
collect the items into |
separate_with |
separate the items with ✅ |
insert_between |
insert (separator) between the items 🤔 |
I love a good bikeshedding just as everyone, yet before this Tracking Issue is overwhelmed with it, I suggest to wait and see on the merit of https://github.com/rust-lang/rust/issues/79524#issuecomment-2002474737 in it's own right. My guess is that the PR to simply evade blockers now being on I-libs-api-nominated will yield some insights on that.
I just encountered a situation where this method would have been an excellent solution to a problem I was facing, but I was restricted to stable Rust and couldn't use another crate. It's a shame that it's been marked as unstable for so long given that it only seems to be blocked via a naming conflict with itertools.
Renaming seems like a reasonable solution to me, but I would also note that the corresponding depreciation request on the itertools github seemed to point to there not being a full understanding on their part that this was not being marked as stable because of the naming conflict. They wanted to wait for stability to deprecate their own method, leading to the current state of things.
better to have intersperse(seprator, interval)
where the marker needs to spaced every iterval
.
Only problem i see is reconciling the meaning of iterval == 0. It could be
returns a new array just wit markers (this is the worst , )
Examples: [1,1,1,1].iter().intersperse(0,2) -> [1, 1, 0, 1,1, 0]
Also would need a to capture the meaning for some output like intersperse(??) -> [0, 1, 1, 0 , 1, 1]
I specifically ran into this while looking for solution for KZG encoding that requrires a tranfroming a byte stream into 32 byte symbol with the first (big edian) byte to be zero.
https://docs.eigenlayer.xyz/eigenda/rollup-guides/blob-encoding
As it stands , this API looks like a "alternate" implementation of zip() with infinite iterator over the second iterator.
:( looks like a direct transation of this https://hackage.haskell.org/package/base-4.19.1.0/docs/Data-List.html#v:intersperse
Would be gereat to know how to solve this usecase
[elt elt elt sep elt elt elt sep]
[sep elt elt elt sep elt elt elt]
To give an update, we're currently trying to work around the naming conflict with a language-level feature: https://github.com/rust-lang/rust/issues/89151#issuecomment-2063584575
Will there be a way to access the current separator index when using intersperse_with
?
This is a tracking issue for the
Iterator::intersperse
andintersperse_with
methods. It is based onitertools::intersperse
and is the iterator equivalent ofVec::join
.The feature gate for the issue is
#![feature(iter_intersperse)]
.Public API
Steps / History
intersperse
: #79479intersperse_with
: https://github.com/rust-lang/rust/pull/80567impl<I: FusedIterator> FusedIterator for Intersperse<I>
? (Can be added after stabilization, so not urgent.)Unresolved Questions
None.