-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented Observable.x(ConversionFunc) to allow external extensions…
… to Observables.
- Loading branch information
Aaron Tull
committed
Jul 16, 2015
1 parent
96786bb
commit 62345af
Showing
4 changed files
with
134 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package rx; | ||
|
||
import rx.Observable.OnSubscribe; | ||
|
||
/** | ||
* Converts the values emitted by an Observable's OnSubscribe function to a value. | ||
* | ||
* @param <T> the type of values to be consumed | ||
* @param <R> the return type | ||
*/ | ||
public interface ConversionFunc<T, R> { | ||
/** | ||
* Converts the data produced by the provided {@code OnSubscribe function} to a value. | ||
* | ||
* @param onSubscribe a function that produces data to a Subscriber, usually wrapped by an Observable. | ||
* @return an instance of {@code R} | ||
*/ | ||
public R convert(OnSubscribe<T> onSubscribe); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package rx; | ||
|
||
import rx.Observable.OnSubscribe; | ||
import rx.Observable.Operator; | ||
|
||
public class OperatorConversion<T, R> implements ConversionFunc<T, Observable<R>> { | ||
|
||
private Operator<? extends R, ? super T> operator; | ||
|
||
public OperatorConversion(Operator<? extends R, ? super T> operator) { | ||
this.operator = operator; | ||
} | ||
|
||
@Override | ||
public Observable<R> convert(OnSubscribe<T> onSubscribe) { | ||
return Observable.create(wrapSubscriber(onSubscribe)); | ||
} | ||
|
||
protected OnSubscribe<R> wrapSubscriber(final OnSubscribe<T> onSubscribe) { | ||
return Observable.lift(operator, onSubscribe); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters