smol-rs / futures-lite

Futures, streams, and async I/O combinators.
Apache License 2.0
451 stars 26 forks source link

Add `dedupe()` to `StreamExt` #51

Open jquesada2016 opened 2 years ago

jquesada2016 commented 2 years ago

I am surprised this is something not currently implemented for Stream, unless I am missing something. It would be a great addition.

taiki-e commented 2 years ago

It is not surprising that methods that do not exist in Iterator are not implemented in StreamExt. https://doc.rust-lang.org/nightly/std/index.html?search=dedupe

Also, please describe the specific behavior you need. dedupe has at least two patterns (contiguous elements vs all elements).

jquesada2016 commented 2 years ago

In the context of streams, the method which I believe makes most sense is deduping sequential elements, not all elements, as this is an operation more suited for doing in a collection. However, deduping sequential elements can be very handy for implementing signal-type interfaces that are only triggered when an element actually changes.

I understand thinking of streams as just the future equivalent of future-backed iterators (because that seems to be the design intent), however, I think they can be slightly more, mainly, well, streams of data that can be altered, filtered, diverted, etc., in ways an iterator might not be.

At least that's my opinion.