rxdart
rxdart copied to clipboard
Add distinctBy
Stream.fromIterable(['123', 'abc']).distinctBy((value) => value.length),
emitsInOrder(<dynamic>[
'123',
emitsDone
]));
Codecov Report
Merging #396 into master will decrease coverage by
<.01%
. The diff coverage is0%
.
@@ Coverage Diff @@
## master #396 +/- ##
==========================================
- Coverage 93.34% 93.34% -0.01%
==========================================
Files 59 61 +2
Lines 2013 2043 +30
==========================================
+ Hits 1879 1907 +28
- Misses 134 136 +2
Heya,
Thanks for submitting a PR!
However, I think it's best if we try to keep the amount of operators to a minimum,
distinctBy(method)
is only a shorthand to distinct((a, b) => method(a) == method(b))
.
You could do similar things for all other operators too, to suit different special use cases, but in the end, the sheer amount of operators would be too overwhelming even to experienced users.
Plus, you could simply enable this extension in your own project easily.
In RxJava and RxJs, the distinct
operator accepts a selector instead of an equation, that's inconsistent to this. IMO, we should somehow provide an equivalent method.
According to you mention that keep the amount of operators to a minimum. I think the mapTo(T)
is a redundant operator by the way, because it's just a shorthand to map((it) => T)
.
And yes, that's why I created a simple package for that: https://github.com/yongjhih/flutter_ext/blob/master/streamx/lib/streamx.dart https://github.com/yongjhih/flutter_ext/blob/master/rxdartx/lib/rxdartx.dart
Remember, rxdart is built on top of Dart Streams.
In Dart Streams, there's distinct. But with different behavior to Rx in general, where we have distinct and distinctUntilChanged.
So, since distinct is taken, we chose to add distinctUnique and gave it the same signature, i.e. an (a, b) => bool.
The above is confusing to begin with, if we then add alternatives using selectors, we'd get: distinct, distinctBy, distinctUnique, distinctUniqueBy.
...which is my main concern here.
Maybe selectors in general need a separate issue, cos we'd want to be consistent throughout the whole library then.
Just a random thought, but we could make selector alternatives available in a separate lib, ie rxdart/selectors.dart which is an optional import.
That way the common operators would follow Dart standards, where the new import would follow classic Rx standards.
For anyone interested in this extension (distinctBy
), consider my package https://github.com/hoc081098/rxdart_ext 😃