Add the cast operator to Single.#5332
Conversation
Signed-off-by: Mike Burns <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 | ||
| */ |
There was a problem hiding this comment.
nit: param doesn't need final
There was a problem hiding this comment.
@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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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 | ||
| */ |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Sure. Updated to match the code style.
Signed-off-by: Inferno23 <burnsm523@gmail.com>
Signed-off-by: Inferno23 <burnsm523@gmail.com>
| @@ -0,0 +1,27 @@ | |||
| /* | |||
There was a problem hiding this comment.
Probably want to fix these copyright notices :)
There was a problem hiding this comment.
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, | |||
akarnokd
left a comment
There was a problem hiding this comment.
Please fix the copyright headers.
Signed-off-by: Inferno23 <burnsm523@gmail.com>
There was a problem hiding this comment.
Should be onNext(2), same mistake in OperatorCastTest as well.
There was a problem hiding this comment.
@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>

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