-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Adds Observable.sorted method #4264
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
Changes from all commits
d6f9d37
8086258
47adec6
a1465da
26ebeeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11438,6 +11438,57 @@ public final Observable<List<T>> toSortedList(Func2<? super T, ? super T, Intege | |
return lift(new OperatorToObservableSortedList<T>(sortFunction, initialCapacity)); | ||
} | ||
|
||
/** | ||
* Returns an Observable that emits the events emitted by source Observable, in a | ||
* sorted order. Each item emitted by the Observable must implement {@link Comparable} with respect to all | ||
* other items in the sequence. | ||
* | ||
* <p>Note that calling {@code sorted} with long, non-terminating or infinite sources | ||
* might cause {@link OutOfMemoryError} | ||
* | ||
* <dl> | ||
* <dt><b>Backpressure:</b></dt> | ||
* <dd>The operator honors backpressure from downstream and consumes the source {@code Observable} in an | ||
* unbounded manner (i.e., without applying backpressure to it).</dd> | ||
* <dt><b>Scheduler:</b></dt> | ||
* <dd>{@code sorted} does not operate by default on a particular {@link Scheduler}.</dd> | ||
* </dl> | ||
* | ||
* @throws ClassCastException | ||
* if any item emitted by the Observable does not implement {@link Comparable} with respect to | ||
* all other items emitted by the Observable | ||
* @return an Observable that emits the items emitted by the source Observable in sorted order | ||
*/ | ||
@Experimental | ||
public final Observable<T> sorted(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wasn't sure to name it sorted or sort, what do u think ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. may as well call it |
||
return toSortedList().flatMapIterable(UtilityFunctions.<List<T>>identity()); | ||
} | ||
|
||
/** | ||
* Returns an Observable that emits the events emitted by source Observable, in a | ||
* sorted order based on a specified comparison function. | ||
* | ||
* <p>Note that calling {@code sorted} with long, non-terminating or infinite sources | ||
* might cause {@link OutOfMemoryError} | ||
* | ||
* <dl> | ||
* <dt><b>Backpressure:</b></dt> | ||
* <dd>The operator honors backpressure from downstream and consumes the source {@code Observable} in an | ||
* unbounded manner (i.e., without applying backpressure to it).</dd> | ||
* <dt><b>Scheduler:</b></dt> | ||
* <dd>{@code sorted} does not operate by default on a particular {@link Scheduler}.</dd> | ||
* </dl> | ||
* | ||
* @param sortFunction | ||
* a function that compares two items emitted by the source Observable and returns an Integer | ||
* that indicates their sort order | ||
* @return an Observable that emits the items emitted by the source Observable in sorted order | ||
*/ | ||
@Experimental | ||
public final Observable<T> sorted(Func2<? super T, ? super T, Integer> sortFunction) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Too bad we didn't use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @akarnokd would it make sense to add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would cause lambda ambiguity because their similar pattern: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see .. then I would prefer to not add one.. |
||
return toSortedList(sortFunction).flatMapIterable(UtilityFunctions.<List<T>>identity()); | ||
} | ||
|
||
/** | ||
* Modifies the source Observable so that subscribers will unsubscribe from it on a specified | ||
* {@link Scheduler}. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a note about long or non-terminating or infinite sources as they may run out of memory or never finish collecting the elements to be sorted.