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

Tyrannosaurus Rx

0b2600a627d0af06ca6bbf9abe4067af?s=47 James Hughes
September 03, 2014

Tyrannosaurus Rx

Basic overview of Rx (Reactive Extensions)

0b2600a627d0af06ca6bbf9abe4067af?s=128

James Hughes

September 03, 2014
Tweet

More Decks by James Hughes

Other Decks in Programming

Transcript

  1. TYRANNOSAURUS RX

  2. REACTIVE EXTENSIONS

  3. None
  4. Java JS C# Clojure Groovy Scala Kotlin Python Ruby C++

    Haskell
  5. var list = [1,2,3,4,5,6,7]; ! for(var i = 0; i

    < list.length; i++) { console.log(list[i]) }
  6. var list = [1,2,3,4,5,6,7]; ! list.forEach(function(item) { console.log(item) })

  7. var list = [Promise(), Promise()…]; ! list.forEach(function(item) { console.log(item.get()) })

  8. TIME RUINS EVERYTHING

  9. None
  10. None
  11. None
  12. OBSERVABLES LISTS WITH TIME REIFIED EVENT STREAM PUSH BASED

  13. CREATING OBSERVABLES ITERABLE FUTURE/PROMISE EVENTS RULES OBSERVABLE

  14. CREATING OBSERVABLES Observable.from(new String[] { "The Joker", "The Riddler", "Penguin",

    "Catwoman"})
  15. CREATING OBSERVABLES baddies.subscribe((baddie) -> { out.println(baddie + “ is bad.”)

    })
  16. CREATING OBSERVABLES The Joker is bad. The Riddler is bad.

    Penguin is bad. Catwoman is bad.
  17. CREATING OBSERVABLES class _ extends Subscriber<String> { void onCompleted() {}

    void onError(Throwable t) {} void onNext(String s){} }
  18. CREATING OBSERVABLES onNext("The Joker”)

  19. CREATING OBSERVABLES onNext("The Joker”) onNext("The Riddler”)

  20. CREATING OBSERVABLES onNext("The Joker”) onNext("The Riddler”) onNext(“Penguin")

  21. CREATING OBSERVABLES onNext("The Joker”) onNext("The Riddler”) onNext(“Penguin") onNext(“Catwoman")

  22. CREATING OBSERVABLES onCompleted() onNext("The Joker”) onNext("The Riddler”) onNext(“Penguin") onNext(“Catwoman")

  23. ERROR HANDLING onNext("The Joker”)

  24. onNext("The Joker”) onNext("The Riddler”) ERROR HANDLING

  25. X onNext("The Joker”) onNext("The Riddler”) ERROR HANDLING

  26. X onNext("The Joker”) onNext("The Riddler”) onError(ex) ERROR HANDLING

  27. TRANSFORMING OBSERVABLES TURN AN OBSERVABLE OF ONE TYPE INTO ANOTHER

  28. TRANSFORMING OBSERVABLES Observable ints = Observable .interval(1, SECONDS); ! ints.map((i)

    -> i + 1) .map((i) -> i + “ seconds”) .subscribe(out::println)
  29. TRANSFORMING OBSERVABLES map map

  30. TRANSFORMING OBSERVABLES 1 seconds 2 seconds 3 seconds 4 seconds

    ...
  31. TRANSFORMING OBSERVABLES flatMap(), groupBy(), buffer(), window()

  32. FILTERING OBSERVABLES SELECT AND REJECT ITEMS EMITTED BY AN OBSERVABLE

  33. FILTERING OBSERVABLES var keys = Rx.DOM.keypress(el) var ints = keys.filter(isNumeric)

    ! ints.subscribe(console.log)
  34. FILTERING OBSERVABLES filter X X

  35. FILTERING OBSERVABLES distinct(), timeout(), ignoreElements(), throttleFirst(), debounce(), sample(), first(), last(),

    take(), skip()
  36. COMBINING OBSERVABLES COMPOSING MULTIPLE OBSERVABLES INTO A SINGLE OBSERVABLE

  37. COMBINING OBSERVABLES Observable goodies = Observable.from( new String[]{ "Batman", "Robin",

    "Alfred", “Batgirl"}); ! goodies.zipWith(baddies, (g,b) -> g + " punches " + b)
  38. COMBINING OBSERVABLES zipWith

  39. COMBINING OBSERVABLES Batman punches The Joker Robin punches The Riddler

    Alfred punches Penguin Batgirl punches Catwoman
  40. STUFF AND OTHER THINGS retry(), delay(), timestamp(), amb(), defaultIfEmpty(), reduce(),

    count()
  41. None
  42. TYRANNOSAURUS RX