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

Reactive 4TW

Reactive 4TW

Reactive programming is a new big thing for a couple of years now, but it also shrouded with a distrust as any new technology with mindblowing concepts. Lets pretend together that you didn't hear about Reactive and start learning it from scratch!

Alexey Buzdin

September 24, 2015
Tweet

More Decks by Alexey Buzdin

Other Decks in Programming

Transcript

  1. reactive /rɪˈaktɪv/ 1. showing a response to a stimulus. "pupils

    are reactive to light" 2. acting in response to a situation rather than creating or controlling it. "a proactive rather than a reactive approach"
  2. reactive /rɪˈaktɪv/ 1. showing a response to a stimulus. "pupils

    are reactive to light" 2. acting in response to a situation rather than creating or controlling it. "a proactive rather than a reactive approach"
  3. List<Ball> balls = Collections.singletonList(new Ball()); Observable<Ball> pitcher = Observable.from(balls); Observer<Ball>

    batter = new Observer<Ball>() { @Override public void onCompleted() { /* Score! */ } @Override public void onError(Throwable e) { /* Shame */ } @Override public void onNext(Ball ball) { /* Hit! */ } }; pitcher.subscribe(batter);
  4. List<Ball> balls = Collections.singletonList(new Ball()); Observable<Ball> pitcher = Observable.from(balls); Observer<Ball>

    batter = new Observer<Ball>() { @Override public void onCompleted() { /* Score! */ } @Override public void onError(Throwable e) { /* Shame */ } @Override public void onNext(Ball ball) { /* Hit! */ } }; pitcher.subscribe(batter);
  5. List<Ball> balls = Collections.singletonList(new Ball()); Observable<Ball> pitcher = Observable.from(balls); Observer<Ball>

    batter = new Observer<Ball>() { @Override public void onCompleted() { /* Score! */ } @Override public void onError(Throwable e) { /* Shame */ } @Override public void onNext(Ball ball) { /* Hit! */ } }; pitcher.subscribe(batter);
  6. List<Ball> balls = Collections.singletonList(new Ball()); Observable<Ball> pitcher = Observable.from(balls); Observer<Ball>

    batter = new Observer<Ball>() { @Override public void onCompleted() { /* Score! */ } @Override public void onError(Throwable e) { /* Shame */ } @Override public void onNext(Ball ball) { /* Hit! */ } }; pitcher.subscribe(batter);
  7. List<Ball> balls = /* Infinite balls */ Observable<Ball> pitcher =

    Observable.from(balls); Observer<Ball> batter = new Observer<Ball>() { @Override public void onCompleted() { /* Score! */ } @Override public void onError(Throwable e) { /* Shame */ } @Override public void onNext(Ball ball) { /* Hit! */ } }; pitcher.subscribe(batter);
  8. Everything can be a Stream: - collections - user inputs

    - hardware - properties - caches - data structures - etc.
  9. Everything can be a Stream: - collections - user inputs

    - hardware - properties - caches - data structures - etc.
  10. Everything can be a Stream: - collections - user inputs

    - hardware - properties - caches - data structures - etc.
  11. Hardware LocationManager mng = (LocationManager) getSystemService(Context.LOCATION_SERVICE); LocationListener listener = new

    LocationListener() { public void onLocationChanged(Location location) { // Do something } ….. }; locationManager.requestLocationUpdates (LocationManager.NETWORK_PROVIDER, 0, 0, listener);
  12. Everything can be a Stream: - collections - user inputs

    - hardware - properties - caches - data structures - etc.
  13. Everything can be a Stream: - collections - user inputs

    - hardware - properties - caches - data structures - etc.
  14. Everything can be a Stream: - collections - user inputs

    - hardware - properties - caches - data structures - etc.
  15. Everything can be a Stream: - collections - user inputs

    - hardware - properties - caches - data structures - etc.
  16. RealLife RX RxView.clickEvents(tapBtn) .map(new Func1<ViewClickEvent, Integer>() { @Override public Integer

    call(ViewClickEvent onClickEvent) { log("GOT A TAP"); return 1; } }) .buffer(2, TimeUnit.SECONDS) .observeOn(AndroidSchedulers.mainThread()) .subscribe( /* Observer here */)
  17. Q&A