ReactiveX / rxdart

The Reactive Extensions for Dart
http://reactivex.io
Apache License 2.0
3.35k stars 271 forks source link

Distinct ValueStream #689

Open Conrad33 opened 2 years ago

Conrad33 commented 2 years ago

I'm pretty new to this Dart stream stuff so maybe I'm missing something. But, is it possible to have a distinct ValueStream? The distinct method of the ValueStream class returns a regular Stream. I would like to have a distinct stream that I can synchronously grab the last item out of.

hoc081098 commented 1 year ago

You can check my library: https://github.com/hoc081098/rxdart_ext#3-statestream

Conrad33 commented 1 year ago

This seems like it could work, but why does StateSubject.stream return a regular Stream instead of a ValueStream? Is the only way to get the latest value synchronously to use the StateSubject object itself? This means I would have to update the type annotations of the code that uses this.

hoc081098 commented 1 year ago

Thanks for pointing that, it seem to be a bug.

Conrad33 commented 1 year ago

Ok, that'll work then when that is fixed. On a side note, is there a reason this isn't available out of the box with regular Rx dart?

hoc081098 commented 1 year ago

I encountered the same issue 2 years ago when using Flutter & StreamBuilder, I wrote and published distinct_value_connectable_stream. Recently, I merged it to rxdart_ext and rename DistinctValue to State (inspired by Kotlinx Coroutines StateFlow).

On a side note, is there a reason this isn't available out of the box with regular Rx.

Because StateSubject is not a standard Subject in ReactiveX (includes: PublishSubject, BehaviorSubject, AsyncSubject, ReplaySubject). So I decided to publish it in another package (rxdart_ext) :)). I'm afraid including it in rxdart may confuse many users.