Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Demystifying RxJava Subscribers (Øredev 2015)

Demystifying RxJava Subscribers (Øredev 2015)

RxJava is a powerful library for creating and composing streams of data. It can quickly be used to great effect, but a deeper understand of its internals will prevent running into pitfalls later on.

This talk will focus on the core mechanism of how streams are created and observed: subscribers and subscriptions. We will start with an introduction to the contract of the Subscriber type and how it is used by sources to create streams. Then we will touch on operators and how they use subscribers to modify the data flowing through streams. Finally we'll look at how threading behaves in operators like subscribeOn and observeOn.

Only a very basic level of RxJava knowledge is required for this talk. It will be assumed that you have used or at least seen the basics of RxJava's API before.

Video: https://vimeo.com/144812843

Jake Wharton

November 05, 2015
Tweet

More Decks by Jake Wharton

Other Decks in Programming

Transcript

  1. Reactive Streams 1 2 3 4 5 6 [ ]

    for ( in i ) scale( ) i
  2. Reactive Streams 1 2 3 4 5 6 [ ]

    for ( in i ) if ( % 2 == 0) i scale( ) i
  3. Reactive Streams 1 2 3 4 5 6 2 4

    6 filter( % 2 == 0) i
  4. Observable.just( , , , , , ) Reactive Streams 1

    2 3 4 5 6 .filter( -> % 2 == 0) i i
  5. Observable.just( , , , , , ) Reactive Streams 1

    2 3 4 5 6 .filter( -> % 2 == 0) i i .subscribe( -> { }); i 2 4 6
  6. Observable.just(1, 2, 3, 4, 5, 6)
 .filter(i -> i %

    2 == 0)
 .subscribe(new Action1<Integer>() {
 @Override public void call(Integer item) {
 System.out.println(item);
 }
 }); Reactive Streams -> i i i
  7. Subscribers? interface Observer<T> {
 void onNext(T item);
 void onCompleted();
 void

    onError(Throwable t);
 } interface Subscription {
 void unsubscribe();
 boolean isUnsubscribed();
 }
  8. Subscribers? interface Action1<T> {
 void call(T t);
 } interface Observer<T>

    {
 void onNext(T item);
 void onCompleted();
 void onError(Throwable t);
 } interface Subscription {
 void unsubscribe();
 boolean isUnsubscribed();
 }
  9. Subscribers? interface Action1<T> {
 void call(T t);
 } // ...and

    friends! interface Observer<T> {
 void onNext(T item);
 void onCompleted();
 void onError(Throwable t);
 } interface Subscription {
 void unsubscribe();
 boolean isUnsubscribed();
 }
  10. Subscribers? interface Action1<T> {
 void call(T t);
 } // ...and

    friends! interface Func1<T, R> {
 R call(T t);
 } interface Observer<T> {
 void onNext(T item);
 void onCompleted();
 void onError(Throwable t);
 } interface Subscription {
 void unsubscribe();
 boolean isUnsubscribed();
 }
  11. Subscribers? interface Action1<T> {
 void call(T t);
 } // ...and

    friends! interface Func1<T, R> {
 R call(T t);
 }
 // ...and friends! interface Observer<T> {
 void onNext(T item);
 void onCompleted();
 void onError(Throwable t);
 } interface Subscription {
 void unsubscribe();
 boolean isUnsubscribed();
 }
  12. Subscribers? interface Action1<T> {
 void call(T t);
 }X // ...and

    friends! interface Func1<T, R> {
 R call(T t);
 }X
 // ...and friends! interface Observer<T> {
 void onNext(T item);
 void onCompleted();
 void onError(Throwable t);
 }X interface Subscription {
 void unsubscribe();
 boolean isUnsubscribed();
 }X class Observable<T> {
 static <T> Observable<T> create(OnSubscribe<T> f);
 <R> Observable<R> lift(Operator<? extends R, ? super T> operator);
 <R> Observable<R> compose(Transformer<? super T, ? extends R> transformer);
 static <T> Observable<T> amb(Iterable<? extends Observable<? extends T>> sources);
 static <T> Observable<T> amb(Observable<? extends T> o1, Observable<? extends T> o2);
 static <T> Observable<T> amb(Observable<? extends T> o1, Observable<? extends T> o2, Observable<? extends T> o3);
 static <T> Observable<T> amb(Observable<? extends T> o1, Observable<? extends T> o2, Observable<? extends T> o3, Observable<? extends T> o4);
 static <T> Observable<T> amb(Observable<? extends T> o1, Observable<? extends T> o2, Observable<? extends T> o3, Observable<? extends T> o4, Observable<? extends T> o5);
 static <T> Observable<T> amb(Observable<? extends T> o1, Observable<? extends T> o2, Observable<? extends T> o3, Observable<? extends T> o4, Observable<? extends T> o5, Observable<? extends T> o6);
 static <T> Observable<T> amb(Observable<? extends T> o1, Observable<? extends T> o2, Observable<? extends T> o3, Observable<? extends T> o4, Observable<? extends T> o5, Observable<? extends T> o6, Observable<? extends T> o7);
 static <T> Observable<T> amb(Observable<? extends T> o1, Observable<? extends T> o2, Observable<? extends T> o3, Observable<? extends T> o4, Observable<? extends T> o5, Observable<? extends T> o6, Observable<? extends T> o7, Observable<? extends T> o8);
 static <T> Observable<T> amb(Observable<? extends T> o1, Observable<? extends T> o2, Observable<? extends T> o3, Observable<? extends T> o4, Observable<? extends T> o5, Observable<? extends T> o6, Observable<? extends T> o7, Observable<? extends T> o8, Observable<? extends T> o9);
 static <T1, T2, R> Observable<R> combineLatest(Observable<? extends T1> o1, Observable<? extends T2> o2, Func2<? super T1, ? super T2, ? extends R> combineFunction);
 static <T1, T2, T3, R> Observable<R> combineLatest(Observable<? extends T1> o1, Observable<? extends T2> o2, Observable<? extends T3> o3, Func3<? super T1, ? super T2, ? super T3, ? extends R> combineFunction);
 static <T1, T2, T3, T4, R> Observable<R> combineLatest(Observable<? extends T1> o1, Observable<? extends T2> o2, Observable<? extends T3> o3, Observable<? extends T4> o4, Func4<? super T1, ? super T2, ? super T3, ? super T4, ? extends R> combineFunction);
 static <T1, T2, T3, T4, T5, R> Observable<R> combineLatest(Observable<? extends T1> o1, Observable<? extends T2> o2, Observable<? extends T3> o3, Observable<? extends T4> o4, Observable<? extends T5> o5, Func5<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? extends R> combineFunction);
 static <T1, T2, T3, T4, T5, T6, R> Observable<R> combineLatest(Observable<? extends T1> o1, Observable<? extends T2> o2, Observable<? extends T3> o3, Observable<? extends T4> o4, Observable<? extends T5> o5, Observable<? extends T6> o6, Func6<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? static <T1, T2, T3, T4, T5, T6, T7, R> Observable<R> combineLatest(Observable<? extends T1> o1, Observable<? extends T2> o2, Observable<? extends T3> o3, Observable<? extends T4> o4, Observable<? extends T5> o5, Observable<? extends T6> o6, Observable<? extends T7> o7, Func7<? super T1, ? super T2, ? super T3, ? sup static <T1, T2, T3, T4, T5, T6, T7, T8, R> Observable<R> combineLatest(Observable<? extends T1> o1, Observable<? extends T2> o2, Observable<? extends T3> o3, Observable<? extends T4> o4, Observable<? extends T5> o5, Observable<? extends T6> o6, Observable<? extends T7> o7, Observable<? extends T8> o8, Func8<? super static <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> Observable<R> combineLatest(Observable<? extends T1> o1, Observable<? extends T2> o2, Observable<? extends T3> o3, Observable<? extends T4> o4, Observable<? extends T5> o5, Observable<? extends T6> o6, Observable<? extends T7> o7, Observable<? extends T8> o8, Observable static <T, R> Observable<R> combineLatest(List<? extends Observable<? extends T>> sources, FuncN<? extends R> combineFunction);
 static <T> Observable<T> concat(Observable<? extends Observable<? extends T>> observables);
 static <T> Observable<T> concat(Observable<? extends T> t1, Observable<? extends T> t2);
 static <T> Observable<T> concat(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3);
 static <T> Observable<T> concat(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4);
 static <T> Observable<T> concat(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4, Observable<? extends T> t5);
 static <T> Observable<T> concat(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4, Observable<? extends T> t5, Observable<? extends T> t6);
 static <T> Observable<T> concat(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4, Observable<? extends T> t5, Observable<? extends T> t6, Observable<? extends T> t7);
 static <T> Observable<T> concat(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4, Observable<? extends T> t5, Observable<? extends T> t6, Observable<? extends T> t7, Observable<? extends T> t8);
 static <T> Observable<T> concat(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4, Observable<? extends T> t5, Observable<? extends T> t6, Observable<? extends T> t7, Observable<? extends T> t8, Observable<? extends T> t9);
 static <T> Observable<T> defer(Func0<Observable<T>> observableFactory);
 static <T> Observable<T> empty();
 static <T> Observable<T> error(Throwable exception);
 static <T> Observable<T> from(Future<? extends T> future);
 static <T> Observable<T> from(Future<? extends T> future, long timeout, TimeUnit unit);
 static <T> Observable<T> from(Future<? extends T> future, Scheduler scheduler);
 static <T> Observable<T> from(Iterable<? extends T> iterable);
 static <T> Observable<T> from(T[] array);
 static Observable<Long> interval(long interval, TimeUnit unit);
 static Observable<Long> interval(long interval, TimeUnit unit, Scheduler scheduler);
 static Observable<Long> interval(long initialDelay, long period, TimeUnit unit);
 static Observable<Long> interval(long initialDelay, long period, TimeUnit unit, Scheduler scheduler);
 static <T> Observable<T> just(T value);
 static <T> Observable<T> just(T t1, T t2);
 static <T> Observable<T> just(T t1, T t2, T t3);
 static <T> Observable<T> just(T t1, T t2, T t3, T t4);
 static <T> Observable<T> just(T t1, T t2, T t3, T t4, T t5);
 static <T> Observable<T> just(T t1, T t2, T t3, T t4, T t5, T t6);
 static <T> Observable<T> just(T t1, T t2, T t3, T t4, T t5, T t6, T t7);
 static <T> Observable<T> just(T t1, T t2, T t3, T t4, T t5, T t6, T t7, T t8);
 static <T> Observable<T> just(T t1, T t2, T t3, T t4, T t5, T t6, T t7, T t8, T t9);
 static <T> Observable<T> just(T t1, T t2, T t3, T t4, T t5, T t6, T t7, T t8, T t9, T t10);
 static <T> Observable<T> merge(Iterable<? extends Observable<? extends T>> sequences);
 static <T> Observable<T> merge(Iterable<? extends Observable<? extends T>> sequences, int maxConcurrent);
 static <T> Observable<T> merge(Observable<? extends Observable<? extends T>> source);
 static <T> Observable<T> merge(Observable<? extends Observable<? extends T>> source, int maxConcurrent);
 static <T> Observable<T> merge(Observable<? extends T> t1, Observable<? extends T> t2);
 static <T> Observable<T> merge(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3);
 static <T> Observable<T> merge(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4);
 static <T> Observable<T> merge(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4, Observable<? extends T> t5);
 static <T> Observable<T> merge(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4, Observable<? extends T> t5, Observable<? extends T> t6);
 static <T> Observable<T> merge(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4, Observable<? extends T> t5, Observable<? extends T> t6, Observable<? extends T> t7);
 static <T> Observable<T> merge(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4, Observable<? extends T> t5, Observable<? extends T> t6, Observable<? extends T> t7, Observable<? extends T> t8);
 static <T> Observable<T> merge(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4, Observable<? extends T> t5, Observable<? extends T> t6, Observable<? extends T> t7, Observable<? extends T> t8, Observable<? extends T> t9);
 static <T> Observable<T> merge(Observable<? extends T>[] sequences);
 static <T> Observable<T> merge(Observable<? extends T>[] sequences, int maxConcurrent);
 static <T> Observable<T> mergeDelayError(Observable<? extends Observable<? extends T>> source);
 static <T> Observable<T> mergeDelayError(Observable<? extends Observable<? extends T>> source, int maxConcurrent);
 static <T> Observable<T> mergeDelayError(Observable<? extends T> t1, Observable<? extends T> t2);
 static <T> Observable<T> mergeDelayError(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3);
 static <T> Observable<T> mergeDelayError(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4);
 static <T> Observable<T> mergeDelayError(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4, Observable<? extends T> t5);
 static <T> Observable<T> mergeDelayError(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4, Observable<? extends T> t5, Observable<? extends T> t6);
 static <T> Observable<T> mergeDelayError(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4, Observable<? extends T> t5, Observable<? extends T> t6, Observable<? extends T> t7);
 static <T> Observable<T> mergeDelayError(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4, Observable<? extends T> t5, Observable<? extends T> t6, Observable<? extends T> t7, Observable<? extends T> t8);
 static <T> Observable<T> mergeDelayError(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4, Observable<? extends T> t5, Observable<? extends T> t6, Observable<? extends T> t7, Observable<? extends T> t8, Observable<? extends T> t9);
 Observable<Observable<T>> nest();
 static <T> Observable<T> never();
 static Observable<Integer> range(int start, int count);
 static Observable<Integer> range(int start, int count, Scheduler scheduler);
 static <T> Observable<Boolean> sequenceEqual(Observable<? extends T> first, Observable<? extends T> second);
 static <T> Observable<Boolean> sequenceEqual(Observable<? extends T> first, Observable<? extends T> second, Func2<? super T, ? super T, Boolean> equality);
 static <T> Observable<T> switchOnNext(Observable<? extends Observable<? extends T>> sequenceOfSequences);
 static Observable<Long> timer(long delay, TimeUnit unit);
 static Observable<Long> timer(long delay, TimeUnit unit, Scheduler scheduler);
 static <T, Resource> Observable<T> using(Func0<Resource> resourceFactory, Func1<? super Resource, ? extends Observable<? extends T>> observableFactory, Action1<? super Resource> disposeAction);
 static <T, Resource> Observable<T> using(Func0<Resource> resourceFactory, Func1<? super Resource, ? extends Observable<? extends T>> observableFactory, Action1<? super Resource> disposeAction, boolean disposeEagerly);
 static <R> Observable<R> zip(Iterable<? extends Observable<?>> ws, FuncN<? extends R> zipFunction);
 static <R> Observable<R> zip(Observable<? extends Observable<?>> ws, FuncN<? extends R> zipFunction);
 static <T1, T2, R> Observable<R> zip(Observable<? extends T1> o1, Observable<? extends T2> o2, Func2<? super T1, ? super T2, ? extends R> zipFunction);
 static <T1, T2, T3, R> Observable<R> zip(Observable<? extends T1> o1, Observable<? extends T2> o2, Observable<? extends T3> o3, Func3<? super T1, ? super T2, ? super T3, ? extends R> zipFunction);
 static <T1, T2, T3, T4, R> Observable<R> zip(Observable<? extends T1> o1, Observable<? extends T2> o2, Observable<? extends T3> o3, Observable<? extends T4> o4, Func4<? super T1, ? super T2, ? super T3, ? super T4, ? extends R> zipFunction);
 static <T1, T2, T3, T4, T5, R> Observable<R> zip(Observable<? extends T1> o1, Observable<? extends T2> o2, Observable<? extends T3> o3, Observable<? extends T4> o4, Observable<? extends T5> o5, Func5<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? extends R> zipFunction);
 static <T1, T2, T3, T4, T5, T6, R> Observable<R> zip(Observable<? extends T1> o1, Observable<? extends T2> o2, Observable<? extends T3> o3, Observable<? extends T4> o4, Observable<? extends T5> o5, Observable<? extends T6> o6, Func6<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? extends R> static <T1, T2, T3, T4, T5, T6, T7, R> Observable<R> zip(Observable<? extends T1> o1, Observable<? extends T2> o2, Observable<? extends T3> o3, Observable<? extends T4> o4, Observable<? extends T5> o5, Observable<? extends T6> o6, Observable<? extends T7> o7, Func7<? super T1, ? super T2, ? super T3, ? super T4, ? s static <T1, T2, T3, T4, T5, T6, T7, T8, R> Observable<R> zip(Observable<? extends T1> o1, Observable<? extends T2> o2, Observable<? extends T3> o3, Observable<? extends T4> o4, Observable<? extends T5> o5, Observable<? extends T6> o6, Observable<? extends T7> o7, Observable<? extends T8> o8, Func8<? super T1, ? supe static <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> Observable<R> zip(Observable<? extends T1> o1, Observable<? extends T2> o2, Observable<? extends T3> o3, Observable<? extends T4> o4, Observable<? extends T5> o5, Observable<? extends T6> o6, Observable<? extends T7> o7, Observable<? extends T8> o8, Observable<? extends
  13. Subscribers? interface Action1<T> {
 void call(T t);
 }X // ...and

    friends! interface Func1<T, R> {
 R call(T t);
 }X
 // ...and friends! interface Observer<T> {
 void onNext(T item);
 void onCompleted();
 void onError(Throwable t);
 }X interface Subscription {
 void unsubscribe();
 boolean isUnsubscribed();
 }X Observable<T> share();
 Observable<T> single();
 Observable<T> single(Func1<? super T, Boolean> predicate);
 Observable<T> singleOrDefault(T defaultValue);
 Observable<T> singleOrDefault(T defaultValue, Func1<? super T, Boolean> predicate);
 Observable<T> skip(int count);
 Observable<T> skip(long time, TimeUnit unit);
 Observable<T> skip(long time, TimeUnit unit, Scheduler scheduler);
 Observable<T> skipLast(int count);
 Observable<T> skipLast(long time, TimeUnit unit);
 Observable<T> skipLast(long time, TimeUnit unit, Scheduler scheduler);
 <U> Observable<T> skipUntil(Observable<U> other);
 Observable<T> skipWhile(Func1<? super T, Boolean> predicate);
 Observable<T> startWith(Observable<T> values);
 Observable<T> startWith(Iterable<T> values);
 Observable<T> startWith(T t1);
 Observable<T> startWith(T t1, T t2);
 Observable<T> startWith(T t1, T t2, T t3);
 Observable<T> startWith(T t1, T t2, T t3, T t4);
 Observable<T> startWith(T t1, T t2, T t3, T t4, T t5);
 Observable<T> startWith(T t1, T t2, T t3, T t4, T t5, T t6);
 Observable<T> startWith(T t1, T t2, T t3, T t4, T t5, T t6, T t7);
 Observable<T> startWith(T t1, T t2, T t3, T t4, T t5, T t6, T t7, T t8);
 Observable<T> startWith(T t1, T t2, T t3, T t4, T t5, T t6, T t7, T t8, T t9);
 Subscription subscribe();
 Subscription subscribe(Action1<? super T> onNext);
 Subscription subscribe(Action1<? super T> onNext, Action1<Throwable> onError);
 Subscription subscribe(Action1<? super T> onNext, Action1<Throwable> onError, Action0 onComplete);
 Subscription subscribe(Observer<? super T> observer);
 Subscription unsafeSubscribe(Subscriber<? super T> subscriber);
 Subscription subscribe(Subscriber<? super T> subscriber);
 Observable<T> subscribeOn(Scheduler scheduler);
 <R> Observable<R> switchMap(Func1<? super T, ? extends Observable<? extends R>> func);
 Observable<T> take(int count);
 Observable<T> take(long time, TimeUnit unit);
 Observable<T> take(long time, TimeUnit unit, Scheduler scheduler);
 Observable<T> takeFirst(Func1<? super T, Boolean> predicate);
 Observable<T> takeLast(int count);
 Observable<T> takeLast(int count, long time, TimeUnit unit);
 Observable<T> takeLast(int count, long time, TimeUnit unit, Scheduler scheduler);
 Observable<T> takeLast(long time, TimeUnit unit);
 Observable<T> takeLast(long time, TimeUnit unit, Scheduler scheduler);
 Observable<List<T>> takeLastBuffer(int count);
 Observable<List<T>> takeLastBuffer(int count, long time, TimeUnit unit);
 Observable<List<T>> takeLastBuffer(int count, long time, TimeUnit unit, Scheduler scheduler);
 Observable<List<T>> takeLastBuffer(long time, TimeUnit unit);
 Observable<List<T>> takeLastBuffer(long time, TimeUnit unit, Scheduler scheduler);
 <E> Observable<T> takeUntil(Observable<? extends E> other);
 Observable<T> takeWhile(Func1<? super T, Boolean> predicate);
 Observable<T> takeUntil(Func1<? super T, Boolean> stopPredicate);
 Observable<T> throttleFirst(long windowDuration, TimeUnit unit);
 Observable<T> throttleFirst(long skipDuration, TimeUnit unit, Scheduler scheduler);
 Observable<T> throttleLast(long intervalDuration, TimeUnit unit);
 Observable<T> throttleLast(long intervalDuration, TimeUnit unit, Scheduler scheduler);
 Observable<T> throttleWithTimeout(long timeout, TimeUnit unit);
 Observable<T> throttleWithTimeout(long timeout, TimeUnit unit, Scheduler scheduler);
 Observable<TimeInterval<T>> timeInterval();
 Observable<TimeInterval<T>> timeInterval(Scheduler scheduler);
 <U, V> Observable<T> timeout(Func0<? extends Observable<U>> firstTimeoutSelector, Func1<? super T, ? extends Observable<V>> timeoutSelector);
 <U, V> Observable<T> timeout(Func0<? extends Observable<U>> firstTimeoutSelector, Func1<? super T, ? extends Observable<V>> timeoutSelector, Observable<? extends T> other);
 <V> Observable<T> timeout(Func1<? super T, ? extends Observable<V>> timeoutSelector);
 <V> Observable<T> timeout(Func1<? super T, ? extends Observable<V>> timeoutSelector, Observable<? extends T> other);
 Observable<T> timeout(long timeout, TimeUnit timeUnit);
 Observable<T> timeout(long timeout, TimeUnit timeUnit, Observable<? extends T> other);
 Observable<T> timeout(long timeout, TimeUnit timeUnit, Observable<? extends T> other, Scheduler scheduler);
 Observable<T> timeout(long timeout, TimeUnit timeUnit, Scheduler scheduler);
 Observable<Timestamped<T>> timestamp();
 Observable<Timestamped<T>> timestamp(Scheduler scheduler);
 BlockingObservable<T> toBlocking();
 Observable<List<T>> toList();
 <K> Observable<Map<K, T>> toMap(Func1<? super T, ? extends K> keySelector);
 <K, V> Observable<Map<K, V>> toMap(Func1<? super T, ? extends K> keySelector, Func1<? super T, ? extends V> valueSelector);
 <K, V> Observable<Map<K, V>> toMap(Func1<? super T, ? extends K> keySelector, Func1<? super T, ? extends V> valueSelector, Func0<? extends Map<K, V>> mapFactory);
 <K> Observable<Map<K, Collection<T>>> toMultimap(Func1<? super T, ? extends K> keySelector);
 <K, V> Observable<Map<K, Collection<V>>> toMultimap(Func1<? super T, ? extends K> keySelector, Func1<? super T, ? extends V> valueSelector);
 <K, V> Observable<Map<K, Collection<V>>> toMultimap(Func1<? super T, ? extends K> keySelector, Func1<? super T, ? extends V> valueSelector, Func0<? extends Map<K, Collection<V>>> mapFactory);
 <K, V> Observable<Map<K, Collection<V>>> toMultimap(Func1<? super T, ? extends K> keySelector, Func1<? super T, ? extends V> valueSelector, Func0<? extends Map<K, Collection<V>>> mapFactory, Func1<? super K, ? extends Collection<V>> collectionFactory);
 Observable<List<T>> toSortedList();
 Observable<List<T>> toSortedList(Func2<? super T, ? super T, Integer> sortFunction);
 Observable<List<T>> toSortedList(int initialCapacity);
 Observable<List<T>> toSortedList(Func2<? super T, ? super T, Integer> sortFunction, int initialCapacity);
 Observable<T> unsubscribeOn(Scheduler scheduler);
 <U, R> Observable<R> withLatestFrom(Observable<? extends U> other, Func2<? super T, ? super U, ? extends R> resultSelector);
 <TClosing> Observable<Observable<T>> window(Func0<? extends Observable<? extends TClosing>> closingSelector);
 Observable<Observable<T>> window(int count);
 Observable<Observable<T>> window(int count, int skip);
 Observable<Observable<T>> window(long timespan, long timeshift, TimeUnit unit);
 Observable<Observable<T>> window(long timespan, long timeshift, TimeUnit unit, Scheduler scheduler);
 Observable<Observable<T>> window(long timespan, long timeshift, TimeUnit unit, int count, Scheduler scheduler);
 Observable<Observable<T>> window(long timespan, TimeUnit unit);
 Observable<Observable<T>> window(long timespan, TimeUnit unit, int count);
 Observable<Observable<T>> window(long timespan, TimeUnit unit, int count, Scheduler scheduler);
 Observable<Observable<T>> window(long timespan, TimeUnit unit, Scheduler scheduler);
 <TOpening, TClosing> Observable<Observable<T>> window(Observable<? extends TOpening> windowOpenings, Func1<? super TOpening, ? extends Observable<? extends TClosing>> closingSelector);
 <U> Observable<Observable<T>> window(Observable<U> boundary);
 <T2, R> Observable<R> zipWith(Iterable<? extends T2> other, Func2<? super T, ? super T2, ? extends R> zipFunction);
 <T2, R> Observable<R> zipWith(Observable<? extends T2> other, Func2<? super T, ? super T2, ? extends R> zipFunction);
 }
  14. Subscribers? interface Action1<T> {
 void call(T t);
 }X // ...and

    friends! interface Func1<T, R> {
 R call(T t);
 }X
 // ...and friends! interface Observer<T> {
 void onNext(T item);
 void onCompleted();
 void onError(Throwable t);
 }X interface Subscription {
 void unsubscribe();
 boolean isUnsubscribed();
 }X class Observable<T> { Observable(OnSubscribe<T> func)
 // LOL # of methods... }
  15. Subscribers? interface Observer<T> {
 void onNext(T item);
 void onCompleted();
 void

    onError(Throwable t);
 } interface Subscription {
 void unsubscribe();
 boolean isUnsubscribed();
 } class Observable<T> { Observable(OnSubscribe<T> func)
 // LOL # of methods... }
  16. Subscribers? interface Observer<T> {
 void onNext(T item);
 void onCompleted();
 void

    onError(Throwable t);
 } interface Subscription {
 void unsubscribe();
 boolean isUnsubscribed();
 }
  17. Subscribers? interface Subscription {
 void unsubscribe();
 boolean isUnsubscribed();
 }X Observable<String>

    o = Observable.just("Hi!");
 Subscription s = o.subscribe(new Action1<String>() {
 @Override public void call(String item) {
 System.out.println("ITEM: " + item);
 }X
 });
  18. Subscribers? interface Subscription {
 void unsubscribe();
 boolean isUnsubscribed();
 }X Observable<String>

    o = Observable.just("Hi!");
 Subscription s = o.subscribe(new Observer<String>() {
 @Override public void onNext(String item) {
 System.out.println("ITEM: " + item);
 }X @Override public void onError(Throwable e) { e.printStackTrace(); }X
 @Override public void onCompleted() {}
 }); 
 Action1
 call
  19. Subscribers? interface Subscription {
 void unsubscribe();
 boolean isUnsubscribed();
 } Observable<String>

    o = Observable.just("Hi!");
 Subscription s = o.subscribe(); System.out.println(s);
  20. Subscribers! interface Subscription {
 void unsubscribe();
 boolean isUnsubscribed();
 } Observable<String>

    o = Observable.just("Hi!");
 Subscription s = o.subscribe(); System.out.println(s); > rx.observers.SafeSubscriber@2f2c9b19
  21. Subscribers! interface Subscription {
 void unsubscribe();
 boolean isUnsubscribed();
 } Observable<String>

    o = Observable.just("Hi!");
 Subscription s = o.subscribe(); System.out.println(s); > rx.observers.SafeSubscriber@2f2c9b19
  22. /**
 * SafeSubscriber is a wrapper around Subscriber that ensures

    that * the Subscriber complies with the Observable contract.
 */
 class SafeSubscriber<T> extends Subscriber<T> {
 SafeSubscriber(Subscriber<? super T> actual);
 
 Subscriber<? super T> getActual();
 }
  23. /**
 * SafeSubscriber is a wrapper around Subscriber that ensures

    that * the Subscriber complies with the Observable contract.
 */
 class SafeSubscriber<T> extends Subscriber<T> {
 SafeSubscriber(Subscriber<? super T> actual);
 
 Subscriber<? super T> getActual();
 }
  24. /**
 * SafeSubscriber is a wrapper around Subscriber that ensures

    that * the Subscriber complies with the Observable contract.
 */
 class SafeSubscriber<T> extends Subscriber<T> {
 SafeSubscriber(Subscriber<? super T> actual);
 
 Subscriber<? super T> getActual();
 }
  25. /**
 * Provides a mechanism for receiving push-based notifications *

    from Observables, and permits manual unsubscribing from these * Observables.
 */
 abstract class Subscriber<T> implements Observer<T>, Subscription {
 Subscriber();
 Subscriber(Subscriber<?> subscriber);
 
 void add(Subscription s);
 
 void onStart(); 
 void setProducer(Producer p);
 protected void request(long n);
 }
  26. /**
 * Provides a mechanism for receiving push-based notifications *

    from Observables, and permits manual unsubscribing from these * Observables.
 */
 abstract class Subscriber<T> implements Observer<T>, Subscription {
 Subscriber();
 Subscriber(Subscriber<?> subscriber);
 
 void add(Subscription s);
 
 void onStart(); 
 void setProducer(Producer p);
 protected void request(long n);
 }
  27. /**
 * Provides a mechanism for receiving push-based notifications *

    from Observables, and permits manual unsubscribing from these * Observables.
 */
 abstract class Subscriber<T> implements Observer<T>, Subscription {
 Subscriber();
 Subscriber(Subscriber<?> subscriber);
 
 void add(Subscription s);
 
 void onStart(); 
 void setProducer(Producer p);
 protected void request(long n);
 }
  28. Observable<String> o = Observable.just("Hi!");
 Subscription s = o.subscribe(); System.out.println(s); >

    rx.observers.SafeSubscriber@2f2c9b19 SafeSubscriber<?> ss = (SafeSubscriber<?>) s;
  29. Observable<String> o = Observable.just("Hi!");
 Subscription s = o.subscribe(); System.out.println(s); >

    rx.observers.SafeSubscriber@2f2c9b19 SafeSubscriber<?> ss = (SafeSubscriber<?>) s;
 System.out.println(ss.getActual());
  30. Observable<String> o = Observable.just("Hi!");
 Subscription s = o.subscribe(); System.out.println(s); >

    rx.observers.SafeSubscriber@2f2c9b19 SafeSubscriber<?> ss = (SafeSubscriber<?>) s;
 System.out.println(ss.getActual()); > rx.Observable$26@6d311334
  31. Observable<String> o = Observable.just("Hi!");
 Subscription s = o.subscribe(); System.out.println(s); >

    rx.observers.SafeSubscriber@2f2c9b19 SafeSubscriber<?> ss = (SafeSubscriber<?>) s;
 System.out.println(ss.getActual()); > rx.Observable$26@6d311334
  32. Observable<String> o = Observable.just("Hi!");
 Subscription s = o.subscribe(); System.out.println(s); >

    rx.observers.SafeSubscriber@2f2c9b19 SafeSubscriber<?> ss = (SafeSubscriber<?>) s;
 System.out.println(ss.getActual()); > rx.Observable$26@6d311334
  33. Observable<String> o = Observable.just("Hi!");
 Subscription s = o.subscribe(); System.out.println(s); >

    rx.observers.SafeSubscriber@2f2c9b19 SafeSubscriber<?> ss = (SafeSubscriber<?>) s;
 System.out.println(ss.getActual()); > rx.Observable$26@6d311334
  34. Observable<String> o = Observable.just("Hi!");
 Subscription s = o.subscribe(); System.out.println(s); >

    rx.observers.SafeSubscriber@2f2c9b19 SafeSubscriber<?> ss = (SafeSubscriber<?>) s;
 System.out.println(ss.getActual()); > rx.Observable$26@6d311334
  35. public Subscription subscribe() {
 return subscribe(new Subscriber<T>() {
 @Override public

    void onNext(T args) {
 // do nothing
 }
 
 @Override public void onCompleted() {
 // do nothing
 }
 
 @Override public void onError(Throwable e) {
 throw new OnErrorNotImplementedException(e);
 }
 });
 }
  36. public Subscription subscribe() {
 return subscribe(new Subscriber<T>() {
 @Override public

    void onNext(T args) {
 // do nothing
 }
 
 @Override public void onCompleted() {
 // do nothing
 }
 
 @Override public void onError(Throwable e) {
 throw new OnErrorNotImplementedException(e);
 }
 });
 }
  37. public Subscription subscribe() {
 return subscribe(new Subscriber<T>() {
 @Override public

    void onNext(T args) {
 // do nothing
 }X
 
 @Override public void onCompleted() {
 // do nothing
 }X 
 @Override public void onError(Throwable e) {
 throw new OnErrorNotImplementedException(e);
 }X
 });
 }X
  38. public Subscription subscribe(Action1<? super T> onNext) {
 return subscribe(new Subscriber<T>()

    {
 @Override public void onNext(T args) {
 onNext.call(args);
 }X
 
 @Override public void onCompleted() {
 // do nothing
 }X
 
 @Override public void onError(Throwable e) {
 throw new OnErrorNotImplementedException(e);
 }X
 });
 }X 
 
 
 // do nothing
  39. public Subscription subscribe(Action1<? super T> onNext) {
 return subscribe(new Subscriber<T>()

    {
 @Override public void onNext(T args) {
 onNext.call(args);
 }
 
 @Override public void onCompleted() {
 // do nothing
 }
 
 @Override public void onError(Throwable e) {
 throw new OnErrorNotImplementedException(e);
 }
 });
 }
  40. public Subscription subscribe(Action1<? super T> onNext) {
 return subscribe(new Subscriber<T>()

    {
 @Override public void onNext(T args) {
 onNext.call(args);
 }
 
 @Override public void onCompleted() {
 // do nothing
 }
 
 @Override public void onError(Throwable e) {
 throw new OnErrorNotImplementedException(e);
 }
 });
 }
  41. public Subscription subscribe(Action1<? super T> onNext) {
 return subscribe(new Subscriber<T>()

    {
 @Override public void onNext(T args) {
 onNext.call(args);
 }X
 
 @Override public void onCompleted() {
 // do nothing
 }X
 
 @Override public void onError(Throwable e) {
 throw new OnErrorNotImplementedException(e);
 }X
 });
 }X
  42. public Subscription subscribe(Observer<? super T> observer) {
 if (observer instanceof

    Subscriber) {
 return subscribe((Subscriber<? super T>) observer);
 }
 return subscribe(new Subscriber<T>() {
 @Override public void onNext(T args) {
 observer.onNext(args);
 }X 
 @Override public void onCompleted() {
 observer.onCompleted();
 }X
 @Override public void onError(Throwable e) {
 observer.onError(e);
 }X
 });
 }X Action1<? super T> onNext
 
 
 onNext.call(args);
 
 
 
 // do nothing
 
 
 
 throw new OnErrorNotImplementedException(e);
  43. public Subscription subscribe(Observer<? super T> observer) {
 if (observer instanceof

    Subscriber) {
 return subscribe((Subscriber<? super T>) observer);
 }
 return subscribe(new Subscriber<T>() {
 @Override public void onNext(T args) {
 observer.onNext(args);
 } 
 @Override public void onCompleted() {
 observer.onCompleted();
 }
 @Override public void onError(Throwable e) {
 observer.onError(e);
 }
 });
 }
  44. public Subscription subscribe(Observer<? super T> observer) {
 if (observer instanceof

    Subscriber) {
 return subscribe((Subscriber<? super T>) observer);
 }
 return subscribe(new Subscriber<T>() {
 @Override public void onNext(T args) {
 observer.onNext(args);
 } 
 @Override public void onCompleted() {
 observer.onCompleted();
 }
 @Override public void onError(Throwable e) {
 observer.onError(e);
 }
 });
 }
  45. public Subscription subscribe(Observer<? super T> observer) {
 if (observer instanceof

    Subscriber) {
 return subscribe((Subscriber<? super T>) observer);
 }
 return subscribe(new Subscriber<T>() {
 @Override public void onNext(T args) {
 observer.onNext(args);
 } 
 @Override public void onCompleted() {
 observer.onCompleted();
 }
 @Override public void onError(Throwable e) {
 observer.onError(e);
 }
 });
 }
  46. public Subscription subscribe(Observer<? super T> observer) {
 if (observer instanceof

    Subscriber) {
 return subscribe((Subscriber<? super T>) observer);
 }
 return subscribe(new Subscriber<T>() {
 @Override public void onNext(T args) {
 observer.onNext(args);
 }X 
 @Override public void onCompleted() {
 observer.onCompleted();
 }X
 @Override public void onError(Throwable e) {
 observer.onError(e);
 }X
 });
 }X
  47. Observable.subscribe() ↳ Observable.subscribe(Subscriber<? super T>) Observable.subscribe(Action1<? super T>) ↳ Observable.subscribe(Subscriber<?

    super T>) Observable.subscribe(Observer<? super T>) ↳ Observable.subscribe(Subscriber<? super T>)
  48. Observable.subscribe(Action1<? super T>, Action1<Throwable>) ↳ Observable.subscribe(Subscriber<? super T>) Observable.subscribe(Action1<? super

    T>, Action1<Throwable>, Action0) ↳ Observable.subscribe(Subscriber<? super T>) Observable.subscribe(Observer<? super T>) ↳ Observable.subscribe(Subscriber<? super T>) Observable.subscribe() ↳ Observable.subscribe(Subscriber<? super T>) Observable.subscribe(Action1<? super T>) ↳ Observable.subscribe(Subscriber<? super T>)
  49. Observable.subscribe(Subscriber<? super T>) Observable.subscribe(Action1<? super T>, Action1<Throwable>) ↳ Observable.subscribe(Subscriber<? super

    T>) Observable.subscribe(Action1<? super T>, Action1<Throwable>, Action0) ↳ Observable.subscribe(Subscriber<? super T>) Observable.subscribe(Observer<? super T>) ↳ Observable.subscribe(Subscriber<? super T>) Observable.subscribe() ↳ Observable.subscribe(Subscriber<? super T>) Observable.subscribe(Action1<? super T>) ↳ Observable.subscribe(Subscriber<? super T>)
  50. Observable.subscribe(Subscriber<? super T>) ↳ ??? Observable.subscribe(Action1<? super T>, Action1<Throwable>) ↳

    Observable.subscribe(Subscriber<? super T>) Observable.subscribe(Action1<? super T>, Action1<Throwable>, Action0) ↳ Observable.subscribe(Subscriber<? super T>) Observable.subscribe(Observer<? super T>) ↳ Observable.subscribe(Subscriber<? super T>) Observable.subscribe() ↳ Observable.subscribe(Subscriber<? super T>) Observable.subscribe(Action1<? super T>) ↳ Observable.subscribe(Subscriber<? super T>)
  51. Observable<String> o = Observable.just("Hi!");
 Subscription s = o.subscribe(); System.out.println(s); >

    rx.observers.SafeSubscriber@2f2c9b19 SafeSubscriber<?> ss = (SafeSubscriber<?>) s;
 System.out.println(ss.getActual()); > rx.Observable$26@6d311334
  52. Observable<String> o = Observable.just("Hi!");
 Subscriber<String> in = new Subscriber<String>() {


    @Override public void onNext(String item) {
 System.out.println("ITEM: " + item);
 }
 @Override public void onError(Throwable e) {}
 @Override public void onCompleted() {}
 }; Subscription s = o.subscribe(in); SafeSubscriber<?> ss = (SafeSubscriber<?>) s;
 System.out.println(ss.getActual());
  53. Observable<String> o = Observable.just("Hi!");
 Subscriber<String> in = new Subscriber<String>() {


    @Override public void onNext(String item) {
 System.out.println("ITEM: " + item);
 }X
 @Override public void onError(Throwable e) {}X
 @Override public void onCompleted() {}X
 }; Subscription s = o.subscribe(in); SafeSubscriber<?> ss = (SafeSubscriber<?>) s;
 System.out.println(ss.getActual());
  54. Observable<String> o = Observable.just("Hi!");
 Subscriber<String> in = new Subscriber<String>() {


    @Override public void onNext(String item) {
 System.out.println("ITEM: " + item);
 }X
 @Override public void onError(Throwable e) {}X
 @Override public void onCompleted() {}X
 }; System.out.println(in); Subscription s = o.subscribe(in); SafeSubscriber<?> ss = (SafeSubscriber<?>) s;
 System.out.println(ss.getActual());
  55. Observable<String> o = Observable.just("Hi!");
 Subscriber<String> in = new Subscriber<String>() {


    @Override public void onNext(String item) {
 System.out.println("ITEM: " + item);
 }
 @Override public void onError(Throwable e) {}
 @Override public void onCompleted() {}
 }; System.out.println(in); Subscription s = o.subscribe(in); SafeSubscriber<?> ss = (SafeSubscriber<?>) s;
 System.out.println(ss.getActual());
  56. Observable<String> o = Observable.just("Hi!");
 Subscriber<String> in = new Subscriber<String>() {


    @Override public void onNext(String item) {
 System.out.println("ITEM: " + item);
 }
 @Override public void onError(Throwable e) {}
 @Override public void onCompleted() {}
 }; System.out.println(in); Subscription s = o.subscribe(in); SafeSubscriber<?> ss = (SafeSubscriber<?>) s;
 System.out.println(ss.getActual()); > Main$1@eed1f14 > ITEM: Hi! > Main$1@eed1f14
  57. Observations • The consumer of a stream is always a

    Subscriber<T>. • Might be wrapping an Observer<T>, Action1<T>, or just empty.
  58. Observations • The consumer of a stream is always a

    Subscriber<T>. • Might be wrapping an Observer<T>, Action1<T>, or just empty. • Always wrapped in SafeSubscriber<T> to ensure contract.
  59. Observable.subscribe(Subscriber<? super T>) ↳ ??? Observable.subscribe() ↳ Observable.subscribe(Subscriber<? super T>)

    Observable.subscribe(Action1<? super T>) ↳ Observable.subscribe(Subscriber<? super T>) Observable.subscribe(Action1<? super T>, Action1<Throwable>) ↳ Observable.subscribe(Subscriber<? super T>) Observable.subscribe(Action1<? super T>, Action1<Throwable>, Action0) ↳ Observable.subscribe(Subscriber<? super T>) Observable.subscribe(Observer<? super T>) ↳ Observable.subscribe(Subscriber<? super T>)
  60. /**
 * Subscribes to an Observable and provides a Subscriber

    that * implements functions to handle the items the Observable emits * and any error or completion notification it issues.
 */
 public Subscription subscribe(Subscriber<? super T> subscriber) {
 }X
  61. /**
 * Subscribes to an Observable and provides a Subscriber

    that * implements functions to handle the items the Observable emits * and any error or completion notification it issues.
 */
 public Subscription subscribe(Subscriber<? super T> subscriber) {
 if (!(subscriber instanceof SafeSubscriber)) {
 subscriber = new SafeSubscriber<T>(subscriber);
 }Y }X
  62. /**
 * Subscribes to an Observable and provides a Subscriber

    that * implements functions to handle the items the Observable emits * and any error or completion notification it issues.
 */
 public Subscription subscribe(Subscriber<? super T> subscriber) {
 if (!(subscriber instanceof SafeSubscriber)) {
 subscriber = new SafeSubscriber<T>(subscriber);
 }Y onSubscribe.call(subscriber); }X
  63. /**
 * Subscribes to an Observable and provides a Subscriber

    that * implements functions to handle the items the Observable emits * and any error or completion notification it issues.
 */
 public Subscription subscribe(Subscriber<? super T> subscriber) {
 if (!(subscriber instanceof SafeSubscriber)) {
 subscriber = new SafeSubscriber<T>(subscriber);
 }Y onSubscribe.call(subscriber); return subscriber; }X
  64. /**
 * Subscribes to an Observable and provides a Subscriber

    that * implements functions to handle the items the Observable emits * and any error or completion notification it issues.
 */
 public Subscription subscribe(Subscriber<? super T> subscriber) {
 if (!(subscriber instanceof SafeSubscriber)) {
 subscriber = new SafeSubscriber<T>(subscriber);
 }X onSubscribe.call(subscriber); return subscriber; }X class Observable<T> { Observable(OnSubscribe<T> func)
 // LOL # of methods... }
  65. /**
 * Subscribes to an Observable and provides a Subscriber

    that * implements functions to handle the items the Observable emits * and any error or completion notification it issues.
 */
 public Subscription subscribe(Subscriber<? super T> subscriber) {
 if (!(subscriber instanceof SafeSubscriber)) {
 subscriber = new SafeSubscriber<T>(subscriber);
 }X onSubscribe.call(subscriber); return subscriber; }X class Observable<T> { Observable(OnSubscribe<T> func)
 // LOL # of methods... }
  66. /**
 * Subscribes to an Observable and provides a Subscriber

    that * implements functions to handle the items the Observable emits * and any error or completion notification it issues.
 */
 public Subscription subscribe(Subscriber<? super T> subscriber) {
 if (!(subscriber instanceof SafeSubscriber)) {
 subscriber = new SafeSubscriber<T>(subscriber);
 }X onSubscribe.call(subscriber); return subscriber; }X class Observable<T> { Observable(OnSubscribe<T> func)
 // LOL # of methods... }
  67. /**
 * Subscribes to an Observable and provides a Subscriber

    that * implements functions to handle the items the Observable emits * and any error or completion notification it issues.
 */
 public Subscription subscribe(Subscriber<? super T> subscriber) {
 if (!(subscriber instanceof SafeSubscriber)) {
 subscriber = new SafeSubscriber<T>(subscriber);
 }X onSubscribe.call(subscriber); return subscriber; }X interface OnSubscribe<T> extends Action1<Subscriber<? super T>> {
 }
  68. /**
 * Subscribes to an Observable and provides a Subscriber

    that * implements functions to handle the items the Observable emits * and any error or completion notification it issues.
 */
 public Subscription subscribe(Subscriber<? super T> subscriber) {
 if (!(subscriber instanceof SafeSubscriber)) {
 subscriber = new SafeSubscriber<T>(subscriber);
 }X onSubscribe.call(subscriber); return subscriber; }X Action1<Subscriber<? super T>>
  69. Observations • The consumer of a stream is always a

    Subscriber<T>. • Might be wrapping an Observer<T>, Action1<T>, or just empty. • Always wrapped in SafeSubscriber<T> to ensure contract.
  70. Observations • The consumer of a stream is always a

    Subscriber<T>. • Might be wrapping an Observer<T>, Action1<T>, or just empty. • Always wrapped in SafeSubscriber<T> to ensure contract. • Observable<T> is just a helper for passing Subscriber<T> to OnSubscribe<T> (aka Action1<Subscriber<T>>).
  71. Observable<String> greeter = Observable.just("Hi!");
 Subscriber<String> in = new Subscriber<String>() {


    @Override public void onNext(String item) {
 System.out.println("ITEM: " + item);
 }
 @Override public void onError(Throwable e) {}
 @Override public void onCompleted() {}
 }; System.out.println(in); Subscription s = greeter.subscribe(in); SafeSubscriber<?> ss = (SafeSubscriber<?>) s;
 System.out.println(ss.getActual());
  72. Observable<String> greeter = Observable.just("Hi!");
 Subscriber<String> in = new Subscriber<String>() {


    @Override public void onNext(String item) {
 System.out.println("ITEM: " + item);
 }
 @Override public void onError(Throwable e) {}
 @Override public void onCompleted() {}
 }; System.out.println(in); Subscription s = greeter.subscribe(in); SafeSubscriber<?> ss = (SafeSubscriber<?>) s;
 System.out.println(ss.getActual());
  73. static <T> Observable<T> just(final T value) {
 return new Observable<T>(new

    OnSubscribe<T>() {
 @Override public void call(Subscriber<? super T> s) {
 }Y
 });
 }X
  74. static <T> Observable<T> just(final T value) {
 return new Observable<T>(new

    OnSubscribe<T>() {
 @Override public void call(Subscriber<? super T> s) {
 s.onNext(value);
 }Y
 });
 }X
  75. static <T> Observable<T> just(final T value) {
 return new Observable<T>(new

    OnSubscribe<T>() {
 @Override public void call(Subscriber<? super T> s) {
 s.onNext(value);
 s.onCompleted();
 }Y
 });
 }X
  76. Observable<String> greeter = Observable.just("Hi!");
 Subscriber<String> in = new Subscriber<String>() {


    @Override public void onNext(String item) {
 System.out.println("ITEM: " + item);
 }
 @Override public void onError(Throwable e) {}
 @Override public void onCompleted() {}
 }; System.out.println(in); Subscription s = greeter.subscribe(in); SafeSubscriber<?> ss = (SafeSubscriber<?>) s;
 System.out.println(ss.getActual());
  77. Observable<String> greeter = Observable.create(new OnSubscribe<String>() {
 @Override public void call(Subscriber<?

    super String> s) {
 s.onNext("Hi!");
 s.onCompleted();
 }
 });
 Subscriber<String> in = new Subscriber<String>() {
 @Override public void onNext(String item) {
 System.out.println("ITEM: " + item);
 }
 @Override public void onError(Throwable e) {}
 @Override public void onCompleted() {}
 }; System.out.println(in); Subscription s = greeter.subscribe(in); SafeSubscriber<?> ss = (SafeSubscriber<?>) s;
 System.out.println(ss.getActual()); just
  78. Observable<String> greeter = Observable.create(new OnSubscribe<String>() {
 @Override public void call(Subscriber<?

    super String> s) {
 s.onNext("Hi!");
 s.onCompleted();
 }X
 });
 Subscriber<String> in = new Subscriber<String>() {
 @Override public void onNext(String item) {
 System.out.println("ITEM: " + item);
 }Y
 @Override public void onError(Throwable e) {}
 @Override public void onCompleted() {}
 }; System.out.println(in); Subscription s = greeter.subscribe(in); SafeSubscriber<?>XssX= (SafeSubscriber<?>) s;
 System.out.println(ss.getActual()); just
  79. just Observable<String> greeter = Observable.create(new OnSubscribe<String>() {
 @Override public void

    call(Subscriber<? super String> s) { SafeSubscriber<?> ss = (SafeSubscriber<?>) s;
 System.out.println(ss.getActual());
 s.onNext("Hi!");
 s.onCompleted();
 }
 });
 Subscriber<String> in = new Subscriber<String>() {
 @Override public void onNext(String item) {
 System.out.println("ITEM: " + item);
 }Y
 @Override public void onError(Throwable e) {}
 @Override public void onCompleted() {}
 }; System.out.println(in); Subscription s = greeter.subscribe(in); SafeSubscriber<?> ss = (SafeSubscriber<?>) s;
 System.out.println(ss.getActual());
  80. Observable<String> greeter = Observable.create(new OnSubscribe<String>() {
 @Override public void call(Subscriber<?

    super String> s) { SafeSubscriber<?> ss = (SafeSubscriber<?>) s;
 System.out.println(ss.getActual());
 s.onNext("Hi!");
 s.onCompleted();
 }
 });
 Subscriber<String> in = new Subscriber<String>() {
 @Override public void onNext(String item) {
 System.out.println("ITEM: " + item);
 }X
 @Override public void onError(Throwable e) {}
 @Override public void onCompleted() {}
 }; System.out.println(in); Subscription s = greeter.subscribe(in); SafeSubscriber<?> ss = (SafeSubscriber<?>) s;
 System.out.println(ss.getActual()); just
  81. Observable<String> greeter = Observable.create(new OnSubscribe<String>() {
 @Override public void call(Subscriber<?

    super String> s) { SafeSubscriber<?> ss = (SafeSubscriber<?>) s;
 System.out.println(ss.getActual());
 s.onNext("Hi!");
 s.onCompleted();
 }
 });
 Subscriber<String> in = new Subscriber<String>() {
 @Override public void onNext(String item) {
 System.out.println("ITEM: " + item);
 }
 @Override public void onError(Throwable e) {}
 @Override public void onCompleted() {}
 }; System.out.println(in); Subscription s = greeter.subscribe(in); SafeSubscriber<?> ss = (SafeSubscriber<?>) s;
 System.out.println(ss.getActual()); > Main$2@65ab7765 > Main$2@65ab7765 > ITEM: Hi! > Main$2@65ab7765 just
  82. Observable<String> o = Observable.just("Hi!");
 Subscriber<String> in = new Subscriber<String>() {


    @Override public void onNext(String item) {
 System.out.println("ITEM: " + item);
 }X
 @Override public void onError(Throwable e) {}
 @Override public void onCompleted() {}
 }; System.out.println(in); Subscription s = o.subscribe(in); SafeSubscriber<?> ss = (SafeSubscriber<?>) s;
 System.out.println(ss.getActual());
  83. 
 Subscriber<String> in = new Subscriber<String>() {
 @Override public void

    onNext(String item) {
 
 }X
 @Override public void onError(Throwable e) {}
 @Override public void onCompleted() {}
 }; System.out.println(in); in SafeSubscriber<?> ss = (SafeSubscriber<?>) s;
 System.out.println(ss.getActual()); Observable<String> o = Observable.just("Hi!"); Subscription s = o.subscribe(new Action1<String>() {
 @Override public void call(String item) {
 System.out.println("ITEM: " + item);
 }X
 });Z
  84. Observable<Integer> o = Observable.just("Hi!")
 .map(new Func1<String, Integer>() {
 @Override public

    Integer call(String s) {
 return s.length();
 }
 });Y Subscription s = o.subscribe(new Action1<Integer>() {
 @Override public void call(Integer item) {
 System.out.println("ITEM: " + item);
 }X
 });Z
  85. Observable<Integer> o = Observable.just("Hi!")
 .map(new Func1<String, Integer>() {
 @Override public

    Integer call(String s) {
 return s.length();
 }
 });Y Subscription s = o.subscribe(new Action1<Integer>() {
 @Override public void call(Integer item) {
 System.out.println("ITEM: " + item);
 }X
 });Z
  86. Observable<Integer> o = Observable.just("Hi!")
 .map(new Func1<String, Integer>() {
 @Override public

    Integer call(String s) {
 return s.length();
 }
 });Y Subscription s = o.subscribe(new Action1<Integer>() {
 @Override public void call(Integer item) {
 System.out.println("ITEM: " + item);
 }X
 });Z > ITEM: 3
  87. Observable<Integer> o = Observable.just("Hi!")
 .map(new Func1<String, Integer>() {
 @Override public

    Integer call(String s) {
 return s.length();
 }
 });Y Subscription s = o.subscribe(new Action1<Integer>() {
 @Override public void call(Integer item) {
 System.out.println("ITEM: " + item);
 }X
 });Z > ITEM: 3
  88. Observable<Integer> o = Observable.just("Hi!")
 .map(new Func1<String, Integer>() {
 @Override public

    Integer call(String s) {
 return s.length();
 }
 });Y Subscription s = o.subscribe(new Action1<Integer>() {
 @Override public void call(Integer item) {
 System.out.println("ITEM: " + item);
 }X
 });Z > ITEM: 3
  89. <R> Observable<R> map(Func1<? super T, ? extends R> func) {


    return lift(new OperatorMap<T, R>(func));
 }
  90. <R> Observable<R> map(Func1<? super T, ? extends R> func) {


    return lift(new OperatorMap<T, R>(func));
 }
  91. <R> Observable<R> map(Func1<? super T, ? extends R> func) {


    return lift(new OperatorMap<T, R>(func));
 }
  92. <R> Observable<R> map(Func1<? super T, ? extends R> func) {


    return lift(new OperatorMap<T, R>(func));
 }
  93. <R> Observable<R> map(Func1<? super T, ? extends R> func) {


    return lift(new OperatorMap<T, R>(func));
 }
  94. <R> Observable<R> map(Func1<? super T, ? extends R> func) {


    return lift(new OperatorMap<T, R>(func));
 } Observable<T> filter(Func1<? super T, Boolean> predicate) {
 return lift(new OperatorFilter<T>(predicate));
 }
  95. <R> Observable<R> map(Func1<? super T, ? extends R> func) {


    return lift(new OperatorMap<T, R>(func));
 } Observable<T> filter(Func1<? super T, Boolean> predicate) {
 return lift(new OperatorFilter<T>(predicate));
 } <R> Observable<R> scan(R initialValue, Func2<R, ? super T, R> accumulator) {
 return lift(new OperatorScan<R, T>(initialValue, accumulator));
 }
  96. <R> Observable<R> map(Func1<? super T, ? extends R> func) {


    return lift(new OperatorMap<T, R>(func));
 } Observable<T> filter(Func1<? super T, Boolean> predicate) {
 return lift(new OperatorFilter<T>(predicate));
 } <R> Observable<R> scan(R initialValue, Func2<R, ? super T, R> accumulator) {
 return lift(new OperatorScan<R, T>(initialValue, accumulator));
 } <U, R> Observable<R> withLatestFrom(Observable<? extends U> other, Func2<? super T, ? super U, ? extends R> resultSelector) {
 return lift( new OperatorWithLatestFrom<T, U, R>(other, resultSelector));
 }
  97. <R> Observable<R> lift(Operator<? extends R, ? super T> operator) {


    }X interface Operator<R, T> extends Func1<Subscriber<? super R>, Subscriber<? super T>> {
 }X
  98. <R> Observable<R> lift(Operator<? extends R, ? super T> operator) {


    }X Observable.just("Hi!")
 .map(s -> s.length()) .subscribe( new Action1<Integer> {..}); interface Operator<R, T> extends Func1<Subscriber<? super R>, Subscriber<? super T>> {
 }X
  99. <R> Observable<R> lift(Operator<? extends R, ? super T> operator) {


    }X Observable.just("Hi!")
 .map(s -> s.length()) .subscribe( new Action1<Integer> {..}); Func1<String, Integer> interface Operator<R, T> extends Func1<Subscriber<? super R>, Subscriber<? super T>> {
 }
  100. <R> Observable<R> lift(Operator<? extends R, ? super T> operator) {


    }X Observable.just("Hi!")
 .map(s -> s.length()) .subscribe( new Action1<Integer> {..}); Func1<String, Integer> Operator<Integer, String> interface Operator<R, T> extends Func1<Subscriber<? super R>, Subscriber<? super T>> {
 }X
  101. <R> Observable<R> lift(Operator<? extends R, ? super T> operator) {


    }X Observable.just("Hi!")
 .map(s -> s.length()) .subscribe( new Action1<Integer> {..}); interface Operator<R, T> extends Func1<Subscriber<? super R>, Subscriber<? super T>> {
 }X
  102. <R> Observable<R> lift(Operator<? extends R, ? super T> operator) {


    }X Observable.just("Hi!")
 .map(s -> s.length()) .subscribe( new Action1<Integer> {..}); Subscriber<Integer> interface Operator<R, T> extends Func1<Subscriber<? super R>, Subscriber<? super T>> {
 }X
  103. <R> Observable<R> lift(Operator<? extends R, ? super T> operator) {


    } Observable.just("Hi!")
 .map(s -> s.length()) .subscribe( new Action1<Integer> {..}); Subscriber<String> interface Operator<R, T> extends Func1<Subscriber<? super R>, Subscriber<? super T>> {
 } Subscriber<Integer>
  104. <R> Observable<R> lift(Operator<? extends R, ? super T> operator) {


    }X Observable.just("Hi!")
 .map(s -> s.length()) .subscribe( new Action1<Integer> {..}); Subscriber<String> interface Operator<R, T> extends Func1<Subscriber<? super R>, Subscriber<? super T>> {
 }X Operator<Integer, String> Subscriber<Integer>
  105. <R> Observable<R> lift(Operator<? extends R, ? super T> operator) {


    }X Observable.just("Hi!")
 .map(s -> s.length()) .subscribe( new Action1<Integer> {..}); Subscriber<String> interface Operator<R, T> extends Func1<Subscriber<? super R>, Subscriber<? super T>> {
 }X Func1<Subscriber<Integer>, Subscriber<String>> Subscriber<Integer> Operator< , >
  106. <R> Observable<R> lift(Operator<? extends R, ? super T> operator) {


    return new Observable<R>(new OnSubscribe<R>() {
 @Override public void call(Subscriber<? super R> sr) {
 }Y
 });
 }X
  107. <R> Observable<R> lift(Operator<? extends R, ? super T> operator) {


    return new Observable<R>(new OnSubscribe<R>() {
 @Override public void call(Subscriber<? super R> sr) {
 Subscriber<? super T> st = operator.call(sr);
 }Y
 });
 }X
  108. <R> Observable<R> lift(Operator<? extends R, ? super T> operator) {


    return new Observable<R>(new OnSubscribe<R>() {
 @Override public void call(Subscriber<? super R> sr) {
 Subscriber<? super T> st = operator.call(sr);
 onSubscribe.call(st);
 }Y
 });
 }X
  109. <R> Observable<R> map(Func1<? super T, ? extends R> func) {


    return lift(new OperatorMap<T, R>(func));
 }
  110. final class OperatorMap<T, R> implements Operator<R, T> {
 private final

    Func1<? super T, ? extends R> func;
 
 OperatorMap(Func1<? super T, ? extends R> func) {
 this.func = func;
 }W
 }X
  111. final class OperatorMap<T, R> implements Operator<R, T> {
 private final

    Func1<? super T, ? extends R> func;
 
 OperatorMap(Func1<? super T, ? extends R> func) {
 this.func = func;
 }W
 
 @Override public Subscriber<? super T> call(final Subscriber<? super R> o) {
 }Y
 }X
  112. final class OperatorMap<T, R> implements Operator<R, T> {
 private final

    Func1<? super T, ? extends R> func;
 
 OperatorMap(Func1<? super T, ? extends R> func) {
 this.func = func;
 }W
 
 @Override public Subscriber<? super T> call(final Subscriber<? super R> o) {
 return new Subscriber<T>(o) { };
 }Y
 }X
  113. final class OperatorMap<T, R> implements Operator<R, T> {
 private final

    Func1<? super T, ? extends R> func;
 
 OperatorMap(Func1<? super T, ? extends R> func) {
 this.func = func;
 }W
 
 @Override public Subscriber<? super T> call(final Subscriber<? super R> o) {
 return new Subscriber<T>(o) {
 @Override public void onNext(T t) {
 o.onNext(func.call(t));
 }Z
 };
 }Y
 }X
  114. final class OperatorMap<T, R> implements Operator<R, T> {
 private final

    Func1<? super T, ? extends R> func;
 
 OperatorMap(Func1<? super T, ? extends R> func) {
 this.func = func;
 }W
 
 @Override public Subscriber<? super T> call(final Subscriber<? super R> o) {
 return new Subscriber<T>(o) {
 @Override public void onNext(T t) {
 o.onNext(func.call(t));
 }Z 
 @Override public void onCompleted() { o.onCompleted(); }
 @Override public void onError(Throwable e) { o.onError(e); }
 };
 }Y
 }X
  115. Observations • The consumer of a stream is always a

    Subscriber<T>. • Might be wrapping an Observer<T>, Action1<T>, or just empty. • Always wrapped in SafeSubscriber<T> to ensure contract. • Observable<T> is just a helper for passing Subscriber<T> to OnSubscribe<T> (aka Action1<Subscriber<T>>).
  116. Observations • The consumer of a stream is always a

    Subscriber<T>. • Might be wrapping an Observer<T>, Action1<T>, or just empty. • Always wrapped in SafeSubscriber<T> to ensure contract. • Observable<T> is just a helper for passing Subscriber<T> to OnSubscribe<T> (aka Action1<Subscriber<T>>). • 
 • Operator<T,R> (aka Func1<Subscriber<R>,Subscriber<T>>) changes Observable<T> to Observable<R> via lift().
  117. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> Observable.just("Hi!") .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Subscriber<String> onComplete() 3 SafeSubscriber<Integer>
  118. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> Observable.just("Hi!") .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Subscriber<String> onComplete() 3 SafeSubscriber<Integer>
  119. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> Observable.just("Hi!") .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> SafeSubscriber<Integer> onComplete() 3 Subscriber<String>
  120. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> Observable.just("Hi!") .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<String> OnSubscribe<String> Operator<String, String> .observeOn(computation())
  121. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> Observable.just("Hi!") .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<String> OnSubscribe<String> Operator<String, String> .observeOn(computation()) "Hi!"
  122. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> Observable.just("Hi!") .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<String> OnSubscribe<String> Operator<String, String> .observeOn(computation()) "Hi!"
  123. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> Observable.just("Hi!") .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<String> OnSubscribe<String> Operator<String, String> .observeOn(computation()) "Hi!"
  124. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> Observable.just("Hi!") .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<String> OnSubscribe<String> Operator<String, String> .observeOn(computation()) "Hi!"
  125. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> Observable.just("Hi!") .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<String> OnSubscribe<String> Operator<String, String> .observeOn(computation()) 3
  126. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> Observable.just("Hi!") .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<String> OnSubscribe<String> Operator<String, String> .observeOn(computation()) 3
  127. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> Observable.just("Hi!") .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<String> OnSubscribe<String> Operator<String, String> .observeOn(computation())
  128. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> Observable.just("Hi!") .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .observeOn(computation())
  129. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> Observable.just("Hi!") .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .observeOn(computation()) "Hi!"
  130. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> Observable.just("Hi!") .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .observeOn(computation()) "Hi!"
  131. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> Observable.just("Hi!") .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .observeOn(computation()) "Hi!"
  132. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> Observable.just("Hi!") .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .observeOn(computation()) 3
  133. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> Observable.just("Hi!") .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .observeOn(computation()) 3
  134. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> Observable.just("Hi!") .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .observeOn(computation()) 3
  135. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> Observable.just("Hi!") .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .observeOn(computation()) 3
  136. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> Observable.just("Hi!") .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .observeOn(computation())
  137. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> Observable.just("Hi!") .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .observeOn(computation()) Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .subscribeOn(io())
  138. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> Observable.just("Hi!") .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .observeOn(computation()) Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .subscribeOn(io())
  139. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> Observable.just("Hi!") .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .observeOn(computation()) Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .subscribeOn(io())
  140. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> Observable.just("Hi!") .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .observeOn(computation()) "Hi!" Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .subscribeOn(io())
  141. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> httpApi.sayHi() .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .observeOn(computation()) "Hi!" Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .subscribeOn(io())
  142. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> httpApi.sayHi() .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .observeOn(computation()) "Hi!" Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .subscribeOn(io())
  143. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> httpApi.sayHi() .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .observeOn(computation()) "Hi!" Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .subscribeOn(io())
  144. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> httpApi.sayHi() .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .observeOn(computation()) Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .subscribeOn(io()) 3
  145. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> httpApi.sayHi() .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .observeOn(computation()) Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .subscribeOn(io()) 3
  146. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> httpApi.sayHi() .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .observeOn(computation()) Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .subscribeOn(io()) 3
  147. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> httpApi.sayHi() .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .observeOn(computation()) Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .subscribeOn(io()) 3
  148. Observable<String> OnSubscribe<String> Observable<Integer> OnSubscribe<Integer> Operator<Integer, String> Action1<Integer> httpApi.sayHi() .map(s ->

    s.length()) .subscribe(..) Func1<String, Integer> Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .observeOn(computation()) Observable<Integer> OnSubscribe<Integer> Operator<Integer, Integer> .subscribeOn(io()) 3
  149. Observations • The consumer of a stream is always a

    Subscriber<T>. • Observable<T> is just a helper for passing Subscriber<T> to OnSubscribe<T> (aka Action1<Subscriber<T>>). • Operator<T,R> (aka Func1<Subscriber<R>,Subscriber<T>>) changes Observable<T> to Observable<R> via lift().
  150. Observations • The consumer of a stream is always a

    Subscriber<T>. • Observable<T> is just a helper for passing Subscriber<T> to OnSubscribe<T> (aka Action1<Subscriber<T>>). • Operator<T,R> (aka Func1<Subscriber<R>,Subscriber<T>>) changes Observable<T> to Observable<R> via lift(). • subscribeOn() and observeOn() are operators which change the thread a Subscriber<T> subscribes on and is called on, respectively.
  151. More Resources • Use the source!
 https://github.com/ReactiveX/RxJava/ • "Advanced RxJava"

    blog series by David Karnok
 http://akarnokd.blogspot.hu/ • "What if the user was a function?" by André Staltz
 https://www.youtube.com/watch?v=1zj7M1LnJV4
  152. RxWTF? • ReactiveX homepage
 http://reactivex.io/ • "The introduction to Reactive

    Programming you've been missing"
 https://gist.github.com/staltz/868e7e9bc2a7b8c1f754
  153. RxWTF? • ReactiveX homepage
 http://reactivex.io/ • "The introduction to Reactive

    Programming you've been missing"
 https://gist.github.com/staltz/868e7e9bc2a7b8c1f754 • RxMarbles
 http://rxmarbles.com/
  154. RxWTF? • ReactiveX homepage
 http://reactivex.io/ • "The introduction to Reactive

    Programming you've been missing"
 https://gist.github.com/staltz/868e7e9bc2a7b8c1f754 • RxMarbles
 http://rxmarbles.com/ • Talks by Ben Christensen
 https://speakerdeck.com/benjchristensen