June 2017
Intermediate to advanced
400 pages
8h 44m
English
Single<T> is essentially an Observable<T> that will only emit one item. It works just like an Observable, but it is limited only to operators that make sense for a single emission. It has its own SingleObserver interface as well:
interface SingleObserver<T> { void onSubscribe(Disposable d); void onSuccess(T value); void onError(Throwable error); }
The onSuccess() essentially consolidates onNext() and onComplete() into a single event that accepts the one emission. When you call subscribe() against a Single, you provide the lambdas for onSuccess() as well as an optional onError():
import io.reactivex.Single; public class Launcher { public static void main(String[] args) { Single.just("Hello") .map(String::length) .subscribe(System ...
Read now
Unlock full access