Created
November 26, 2014 10:24
-
-
Save kevroletin/6d6bc64b4a5afb2c2e50 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class MapOnce<T, R> { | |
private final PublishSubject<R> subject = PublishSubject.create(); | |
private MapOnce(Observable<T> source, Function<T, R> func) { | |
source.subscribe((T data) -> { | |
R result = func.apply(data); | |
subject.onNext(result); | |
}); | |
} | |
static public <T,R> Observable<R> apply(Observable<T> source, Function<T, R> func) { | |
return (new MapOnce(source, func)).subject.asObservable(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment