Add the cast operator to Single. by Mikey-Burns · Pull Request #5332 · ReactiveX/RxJava · GitHub
Skip to content

Add the cast operator to Single.#5332

Merged
akarnokd merged 6 commits into
ReactiveX:1.xfrom
Mikey-Burns:singleCast
May 8, 2017
Merged

Add the cast operator to Single.#5332
akarnokd merged 6 commits into
ReactiveX:1.xfrom
Mikey-Burns:singleCast

Conversation

@Mikey-Burns

Copy link
Copy Markdown

Adding the cast operator to Single. This exists in the 2.x branch but not in the 1.x branch, so callers have had to do unnatural operations like .map(SomeClass.class:cast) to get around this. Added tests similar to those for Observable.cast.

Signed-off-by: Mike Burns burnsm523@gmail.com

Signed-off-by: Mike Burns <burnsm523@gmail.com>
@codecov

codecov Bot commented May 4, 2017

Copy link
Copy Markdown

* @param <R> the target type
* @param klass the type token to use for casting the success result from the current Single
* @return the new Single instance
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: param doesn't need final

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@JakeWharton I was following the example of Observable.cast(). Would you like me to remove final from here or shall I leave it to remain consistent?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add @Experimental and @since 1.3.1 - experimental to the javadoc

* @param klass the type token to use for casting the success result from the current Single
* @return the new Single instance
*/
public final <R> Single<R> cast(final Class<R> klass) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I didn't realize you could reuse Observable operators on Singles. There's probably a bit of additional overhead, but the reuse is really nice.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Actually you should not reuse them but develop/port them directly. Especially this type of Map derivative that could be just a Func1 wrapping the cast and delegating to map.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@akarnokd I will update the PR with a simplified implementation. Thanks for the suggestion.

Signed-off-by: Inferno23 <burnsm523@gmail.com>
* @param <R> the target type
* @param klass the type token to use for casting the success result from the current Single
* @return the new Single instance
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add @Experimental and @since 1.3.1 - experimental to the javadoc

*/
public class SingleOperatorCast<T, R> implements Func1<T, R> {

final Class<R> castClass;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

4 spaces.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sure. Updated to match the code style.

@akarnokd akarnokd added this to the 1.4 milestone May 4, 2017
Signed-off-by: Inferno23 <burnsm523@gmail.com>
Signed-off-by: Inferno23 <burnsm523@gmail.com>
@@ -0,0 +1,27 @@
/*

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Probably want to fix these copyright notices :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@dano Thanks!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks @dano. IntelliJ default settings getting the better of me again.

@@ -0,0 +1,42 @@
/*
* This is the confidential unpublished intellectual property of EMC Corporation,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This too.

@akarnokd akarnokd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please fix the copyright headers.

Signed-off-by: Inferno23 <burnsm523@gmail.com>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should be onNext(2), same mistake in OperatorCastTest as well.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@artem-zinnatullin I agree that in OperatorCastTest the second invocation should use 2. However, here I think the second invocation is actually unnecessary because only one item gets emitted from the Single. I can remove this line since it is not needed.

Signed-off-by: Inferno23 <burnsm523@gmail.com>

@artem-zinnatullin artem-zinnatullin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

@akarnokd akarnokd merged commit a5c0cd0 into ReactiveX:1.x May 8, 2017
@Mikey-Burns Mikey-Burns deleted the singleCast branch May 9, 2017 12:52
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.

5 participants