-
Notifications
You must be signed in to change notification settings - Fork 7.6k
2.x changing some Observable operators to return Single. #4321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm +1 for it I also suggested that here for a few operators #4277 |
I don't know, looks like one needs to convert back to |
@akarnokd Why don't the operators on Single return Flowables? Isn't singleSubscribe an implicit request one? As for the unit tests it's a large task but not insurmountable. |
Some do, like |
@akarnokd Yes, I agree Single should not have back pressure because it is fixed size and subscribing can be thought of as an implicit request one. In other words if the subscriber doesn't have enough room in the queue for one element then don't subscribe. |
I'm a bit nervous about Single not supporting backpressure. We got into trouble with |
I agree with @davidmoten. It was clear that a mistake was made with |
The main difference in this case is that Single isn't meant to support back pressure so it wouldn't mix of behavior like there was with just. |
I understand. I just dislike the lack of consistency between the flow control mechanisms on I do get that |
I don't see Single or Completable missing backpressure being a problem in On Wed, Aug 10, 2016, 8:44 PM Lalit Maganti [email protected]
|
It's not necessarily a problem and I guess reworking Single is unfeasible anyway this close to 2.x RC. Just a small gripe I had :) |
Backpressure is there to avoid buffer bloat with unknown length streams. Single has only one element to get buffered and generally not a problem.
Personally, I'd get rid of all but |
Yeah, even 1.x codebase is quite hard to maintain, 2.x with different Flowable/Observable makes it even harder to work with… @akarnokd you can add basic support of |
The reason for The alternative could be to make this dependence indirect via reflection: Single<T> single = someFlowable.to(Single.class);
public Z to(Class<Z> target) {
return (Z)target.getMethod("from", Publisher.class).invoke(null, this);
} but even a cached method may be too expensive on some platforms. Otherwise: someFlowable.to(Single::from).blah().blah();
someSingle.toFlowable(); // Single library depending on Flowable library is okay |
I was talking about this a bit more and noticed that |
There's already an Optional and Try type! On Wed, Aug 17, 2016, 5:44 PM George Campbell [email protected]
|
I'm not sure about Try but isn't |
Ah I see. It's a custom Optional, not Java 8s, so we could make a lazy On Wed, Aug 17, 2016, 7:09 PM George Campbell [email protected]
|
I've been going over method signatures trying to come up with a plan for all of the conversion methods:
From 5 reactive types I want to drop the methods like This is the core of the changes that I'm working on the effects of which will ripple out to all of the unit tests. |
Please don't remove the internal operators backing the original same-type behavior. |
@abersnaze How is your progress on this? I held off changes to 2.x but RC3 time is nearing and I'd like to improve performance on various elements. |
I've got a branch that compiles but they're unit tests that failing for reasons. I'll push my branch to my fork if you want to take over.
|
No. I think it's best if I redo it step-by-step, one operator at a time to rule out test anomalies and also apply optimizations. |
The operator .last() effect 100s of tests.
|
See #4570 |
What should happen with
Should these be merged into the former or the latter of each? |
I picked single, first, last, & ignoreElements over toSingle, toMaybe, & toCompletable because the former were more descriptive of what it does when there more than one value. |
Thanks for the info. |
|
I think that if we are going to make a breaking change to the API that we should also take the opportunity to change the behavior (not throwing exceptions) |
To be clear, this is what can happen:
|
You could postfix "Element" onto the names which has precedence from |
What about
|
Actually, since all other such predicate versions were removed, |
You want me to remove it? |
Yes, but only the Api and please fix up the tests that used it. |
What about |
We need those to jumpstart their respective types without conversion. |
I was looking through the Observable operators and wondering if now would be a good time to change the following methods to return Singles instead of Observables.
Single<Boolean> all(Predicate<? super T> predicate)
Single<Boolean> any(Predicate<? super T> predicate)
<U> Single<U> collect(Callable<? extends U> initialValueSupplier, BiConsumer<? super U, ? super T> collector)
<U> Single<U> collectInto(final U initialValue, BiConsumer<? super U, ? super T> collector)
Single<Boolean> contains(final Object o)
Single<Long> count()
Maybe<T> elementAt(long index)
Single<T> elementAt(long index, T defaultValue)
Maybe<T> firstElement()
Single<T> first(T defaultItem)
Completable ignoreElements()
Single<Boolean> isEmpty()
Maybe<T> lastElement()
Single<T> last(T defaultItem)
Maybe<T> reduce(BiFunction<T, T, T> reducer)
<R> Single<R> reduce(R seed, BiFunction<R, ? super T, R> reducer)
<R> Single<R> reduceWith(Callable<R> seedSupplier, BiFunction<R, ? super T, R> reducer)
Maybe<T> singleElement()
Single<T> single(T defaultItem)
Single<List<T>> toList()
Single<List<T>> toList(final int capacityHint)
<K> Single<Map<K, T>> toMap(final Function<? super T, ? extends K> keySelector)
<K, V> Single<Map<K, V>> toMap(final Function<? super T, ? extends K> keySelector, final Function<? super T, ? extends V> valueSelector)
<K> Single<Map<K, Collection<T>>> toMultimap(Function<? super T, ? extends K> keySelector)
<K, V> Single<Map<K, Collection<V>>> toMultimap(Function<? super T, ? extends K> keySelector, Function<? super T, ? extends V> valueSelector)
Single<List<T>> toSortedList()
Single<List<T>> toSortedList(final Comparator<? super T> comparator)
Single<List<T>> toSortedList(final Comparator<? super T> comparator, int capacityHint)
Single<List<T>> toSortedList(int capacityHint)
(These were removed from the API:)
Single<List<T>> takeLastBuffer(int count)
Single<List<T>> takeLastBuffer(int count, long time, TimeUnit unit)
Single<List<T>> takeLastBuffer(int count, long time, TimeUnit unit, Scheduler scheduler)
Single<List<T>> takeLastBuffer(long time, TimeUnit unit)
Single<List<T>> takeLastBuffer(long time, TimeUnit unit, Scheduler scheduler)
The text was updated successfully, but these errors were encountered: