Skip to content

Fix a misleading documentation of Observable.singleElement() #5668

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

Merged
merged 3 commits into from
Oct 15, 2017

Conversation

VeskoI
Copy link
Contributor

@VeskoI VeskoI commented Oct 15, 2017

This PR improves the documentation of Observable.singleElement(), as mentioned in #5317.

An appropriate unit test to verify the empty behaviour already exist (ObservableSingleTest. testSingleWithEmpty()), I just added one more check there to make it very explicit that an error is not thrown.

As a side note, I'm attaching an updated Marble diagram for the method that includes all 3 states of the resulting Maybe (empty, success, error). I believe this is listed in #5319.

singleelement

* Returns a Maybe that emits the single item emitted by this Observable if this Observable
* emits only a single item, otherwise if this Observable emits more than one item or no items, an
* {@code IllegalArgumentException} or {@code NoSuchElementException} is signalled respectively.
* Returns a Maybe that emits the single item emitted by this Observable or completes if this Observable is empty.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with two sentences is that most IDEs and the Javadoc method listing shows only the first sentence. Could you rewrite it that all relevant behavior is in the same sentence?

@codecov
Copy link

codecov bot commented Oct 15, 2017

Codecov Report

Merging #5668 into 2.x will decrease coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##                2.x    #5668      +/-   ##
============================================
- Coverage     96.22%   96.21%   -0.01%     
- Complexity     5814     5816       +2     
============================================
  Files           633      633              
  Lines         41553    41553              
  Branches       5752     5752              
============================================
- Hits          39984    39980       -4     
+ Misses          628      626       -2     
- Partials        941      947       +6
Impacted Files Coverage Δ Complexity Δ
src/main/java/io/reactivex/Observable.java 100% <ø> (ø) 508 <0> (ø) ⬇️
...erators/completable/CompletableConcatIterable.java 95.91% <0%> (-4.09%) 2% <0%> (ø)
...tivex/internal/observers/FutureSingleObserver.java 94.33% <0%> (-3.78%) 24% <0%> (-1%)
.../io/reactivex/internal/schedulers/IoScheduler.java 89.24% <0%> (-3.23%) 9% <0%> (ø)
.../internal/disposables/ListCompositeDisposable.java 98% <0%> (-2%) 34% <0%> (-1%)
...nternal/operators/observable/ObservableWindow.java 98% <0%> (-2%) 3% <0%> (ø)
...nternal/operators/observable/ObservableCreate.java 98.29% <0%> (-1.71%) 2% <0%> (ø)
...x/internal/operators/flowable/FlowablePublish.java 93.83% <0%> (-1.33%) 11% <0%> (ø)
...l/operators/observable/ObservableFlatMapMaybe.java 84.96% <0%> (-1.31%) 2% <0%> (ø)
...ternal/operators/completable/CompletableMerge.java 96.42% <0%> (-1.2%) 2% <0%> (ø)
... and 24 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5387e20...c261434. Read the comment docs.

@akarnokd
Copy link
Member

Here is the standard link for the marble:

https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/singleElement.o.png

@VeskoI
Copy link
Contributor Author

VeskoI commented Oct 15, 2017

Thanks, updated the JavaDoc to include the Marble diagram :)

@akarnokd akarnokd added this to the 2.2 milestone Oct 15, 2017
@@ -282,6 +282,7 @@ public void testSingleWithEmpty() {

InOrder inOrder = inOrder(observer);
inOrder.verify(observer).onComplete();
inOrder.verify(observer, never()).onError(any(Throwable.class));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually covered by verifyNoMoreInteractions but being explicit here doesn't hurt.

@akarnokd akarnokd merged commit cd6bc08 into ReactiveX:2.x Oct 15, 2017
mithunsasidharan added a commit to mithunsasidharan/RxJava that referenced this pull request Oct 15, 2017
Fix a misleading documentation of Observable.singleElement() (ReactiveX#5668)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants