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

Intro to Reactive Programming and RxJava: How to React 😮😱🤪

Intro to Reactive Programming and RxJava: How to React 😮😱🤪

Approach programming in a new way by using Reactive Programming, a functional style that focuses on the flow and manipulation of data. You already know how to think imperatively, using if-statements and state variables, from your experience programming in C. We will discuss the history of Imperative and Reactive programming and compare the different styles with concrete code examples in Java. By the end of this talk you will understand when to use reactive programming and how powerful and succinct it is for data problems.

15019b1cef68cc081d0ca67a32012c86?s=128

Jordan Jozwiak

October 01, 2018
Tweet

Transcript

  1. Intro to Reactive Programming and RxJava: How to React Jordan

    Jozwiak
  2. Reactive Programming Allows us to manipulate a stream of data

    with functions.

  3. Reactive Programming Allows us to manipulate a stream of data

    with functions.
 (asynchronously)
  4. Reactive Programming

  5. Reactive Programming 1. Data streams


  6. Reactive Programming 1. Data streams
 2. Functional Programming


  7. Reactive Programming 1. Data streams
 2. Functional Programming
 3. Asynchronous

    observers
  8. applications ! Retrieving data from a database and then filtering

    out some results based on user settings.
  9. applications ! Retrieving data from a database and then filtering

    out some results based on user settings. 2 3 7
  10. applications ! Retrieving data from a database and then filtering

    out some results based on user settings. ⏳
  11. applications ! Retrieving data from a database and then filtering

    out some results based on user settings. a, b, c -> a, c
  12. applications ! Retrieve data from a database and then filtering

    out some results based on user settings. ! Render a UI that combines data from multiple data sources ! Create a real-time model for stock prices ! Show auto-complete search results to a user ! Log data from a temperature, wind, or pressure sensor
  13. Who actually uses this?

  14. Who actually uses this? ! Very popular in the Android

    community
  15. Who actually uses this? ! Very popular in the Android

    community ! Some usage at Google for database requests
  16. Who actually uses this? ! Very popular in the Android

    community ! Some usage at Google for database requests ! Microsoft, Netflix, GitHub, SoundCloud, and more (see reactivex.io)
  17. Reactive Programming Theory

  18. Reactive Programming Theory Implementation Reactive Extensions (reactivex.io) (libraries to make

    normal languages reactive)
  19. Reactive Programming Theory Implementation Reactive Extensions (reactivex.io) (libraries to make

    normal languages reactive) RxJava RxSwift RxJS …
  20. None
  21. 4 2 1 7 6

  22. 4 2 1 7 6 filter(x -> (x % 2)

    == 0)
  23. 4 2 1 7 6 filter(x -> (x % 2)

    == 0)
  24. 4 2 1 7 6 filter(x -> (x % 2)

    == 0) 4
  25. 4 2 1 7 6 filter(x -> (x % 2)

    == 0) 4 2
  26. 4 2 1 7 6 filter(x -> (x % 2)

    == 0) 4 2 6
  27. 4 2 1 7 6 filter(x -> (x % 2)

    == 0) 4 2 6
  28. 4 2 1 7 6 SUBJECT subject - the stream

    that emits data 4 2 6
  29. 4 2 6 OBSERVER observer - “subscribes to” or “consumes”

    data. There can be multiple observers for a single subject. 4 2 1 7 6
  30. 4 2 1 7 6 filter(x -> (x % 2)

    == 0) 4 2 6 SUBJECT OBSERVER
  31. 4 2 1 7 6 filter(x -> (x % 2)

    == 0) 4 2 6 SUBJECT OBSERVER 4 2 6 SERVER 2
  32. 4 2 1 7 6 filter / map / count

    / 
 max / min / delay / ... SUBJECT OBSERVER
  33. 4 2 1 7 6 some function that takes ⏳

    SUBJECT OBSERVER
  34. 4 2 1 7 6 some function that takes ⏳

    SUBJECT OBSERVER
  35. a d z a h some function that takes ⏳

    SUBJECT OBSERVER
  36. some function that takes ⏳ SUBJECT OBSERVER

  37. ? ? ? ? ? some function that takes ⏳

    ? ? ? ? SUBJECT OBSERVER
  38. some function that takes ⏳ SUBJECT OBSERVER another function

  39. ? ? ? ? ? some function that takes ⏳

    ? ? ? ? SUBJECT OBSERVER another function ? ? ? ? ?
  40. What creates the subject data stream?

  41. What creates the subject data stream? ! These streams are

    called Observables in RxJava
  42. What creates the subject data stream? ! These streams are

    called Observables in RxJava ! Observable.create(), fromIterable(), etc.
  43. What creates the subject data stream? ! These streams are

    called Observables in RxJava ! Observable.create(), fromIterable(), etc. ! Retrofitting existing object-oriented design into Observable data streams can be messy
  44. What creates the subject data stream? ! These streams are

    called Observables in RxJava ! Observable.create(), fromIterable(), etc. ! Retrofitting existing object-oriented design into Observable data streams can be messy ! Many, many open-source projects that wrap other implementations into an Rx package (an easy way to get ⭐ ⭐ ⭐ on GitHub)
  45. What creates the subject data stream? ! These streams are

    called Observables in RxJava ! Observable.create(), fromIterable(), etc. ! Retrofitting existing object-oriented design into Observable data streams can be messy ! Many, many open-source projects that wrap other implementations into an Rx package (an easy way to get ⭐ ⭐ ⭐ on GitHub) ! github.com/zsoltk/RxAndroidLibs - 500 stars for a list of libraries
  46. introduction background examples live demo wrap-up

  47. What languages are you familiar with?

  48. ~80 % Percent of the most popular languages are imperative

    
 or multi-paradigmatic languages Source: StackOverflow Developer Survey 2018
  49. What's a language paradigm?

  50. What's a language paradigm? ! Computer languages resemble linguistic language

  51. What's a language paradigm? ! Computer languages resemble linguistic language

    ◦ Grammatical structures
  52. What's a language paradigm? ! Computer languages resemble linguistic language

    ◦ Grammatical structures ◦ Tenses: past, present, future
  53. What's a language paradigm? ! Computer languages resemble linguistic language

    ◦ Grammatical structures ◦ Tenses: past, present, future ◦ Vocabulary
  54. What's a language paradigm? ! Computer languages resemble linguistic language

    ◦ Grammatical structures ◦ Tenses: past, present, future ◦ Vocabulary ◦ Dialects
  55. What's a language paradigm? ! Computer languages resemble linguistic language

    ◦ Grammatical structures ◦ Tenses: past, present, future ◦ Vocabulary ◦ Dialects ! Languages are multi-faceted and evolve over time. They are often multi- paradigmatic languages.
  56. What's a language paradigm? ! Computer languages resemble linguistic language

    ◦ Grammatical structures ◦ Tenses: past, present, future ◦ Vocabulary ◦ Dialects ! Languages are multi-faceted and evolve over time. They are often multi- paradigmatic languages. ! Examples
  57. What's a language paradigm? ! Computer languages resemble linguistic language

    ◦ Grammatical structures ◦ Tenses: past, present, future ◦ Vocabulary ◦ Dialects ! Languages are multi-faceted and evolve over time. They are often multi- paradigmatic languages. ! Examples ◦ Imperative (what you’re probably used to)
  58. What's a language paradigm? ! Computer languages resemble linguistic language

    ◦ Grammatical structures ◦ Tenses: past, present, future ◦ Vocabulary ◦ Dialects ! Languages are multi-faceted and evolve over time. They are often multi- paradigmatic languages. ! Examples ◦ Imperative (what you’re probably used to) ◦ Reactive Programming (what we’re talking about today)
  59. What's a language paradigm? ! Computer languages resemble linguistic language

    ◦ Grammatical structures ◦ Tenses: past, present, future ◦ Vocabulary ◦ Dialects ! Languages are multi-faceted and evolve over time. They are often multi- paradigmatic languages. ! Examples ◦ Imperative (what you’re probably used to) ◦ Reactive Programming (what we’re talking about today) ◦ Functional Programming (used in Reactive Programming)
  60. Imperative vs. Functional

  61. Imperative vs. Functional Imperative Programming

  62. Imperative vs. Functional Imperative Programming ! Describes how the program

    operates
  63. Imperative vs. Functional Imperative Programming ! Describes how the program

    operates ! Uses statements to change state of the program
  64. Imperative vs. Functional Imperative Programming ! Describes how the program

    operates ! Uses statements to change state of the program ! Conditional statements, loops, inheritance
  65. Imperative vs. Functional Imperative Programming ! Describes how the program

    operates ! Uses statements to change state of the program ! Conditional statements, loops, inheritance ! Easier initial learning curve
  66. Imperative vs. Functional Imperative Programming ! Describes how the program

    operates ! Uses statements to change state of the program ! Conditional statements, loops, inheritance ! Easier initial learning curve ! Examples: C, PHP, Java
  67. Imperative vs. Functional Imperative Programming ! Describes how the program

    operates ! Uses statements to change state of the program ! Conditional statements, loops, inheritance ! Easier initial learning curve ! Examples: C, PHP, Java if (value % 2 == 0) { // do something }
  68. Imperative vs. Functional Imperative Programming ! Describes how the program

    operates ! Uses statements to change state of the program ! Conditional statements, loops, inheritance ! Easier initial learning curve ! Examples: C, PHP, Java Functional Programming if (value % 2 == 0) { // do something }
  69. Imperative vs. Functional Imperative Programming ! Describes how the program

    operates ! Uses statements to change state of the program ! Conditional statements, loops, inheritance ! Easier initial learning curve ! Examples: C, PHP, Java Functional Programming ! Describes what the program should accomplish if (value % 2 == 0) { // do something }
  70. Imperative vs. Functional Imperative Programming ! Describes how the program

    operates ! Uses statements to change state of the program ! Conditional statements, loops, inheritance ! Easier initial learning curve ! Examples: C, PHP, Java Functional Programming ! Describes what the program should accomplish ! Ideally stateless if (value % 2 == 0) { // do something }
  71. Imperative vs. Functional Imperative Programming ! Describes how the program

    operates ! Uses statements to change state of the program ! Conditional statements, loops, inheritance ! Easier initial learning curve ! Examples: C, PHP, Java Functional Programming ! Describes what the program should accomplish ! Ideally stateless ! Evaluate functions and create expressions instead of statements if (value % 2 == 0) { // do something }
  72. Imperative vs. Functional Imperative Programming ! Describes how the program

    operates ! Uses statements to change state of the program ! Conditional statements, loops, inheritance ! Easier initial learning curve ! Examples: C, PHP, Java Functional Programming ! Describes what the program should accomplish ! Ideally stateless ! Evaluate functions and create expressions instead of statements ! More difficult conceptually if (value % 2 == 0) { // do something }
  73. Imperative vs. Functional Imperative Programming ! Describes how the program

    operates ! Uses statements to change state of the program ! Conditional statements, loops, inheritance ! Easier initial learning curve ! Examples: C, PHP, Java Functional Programming ! Describes what the program should accomplish ! Ideally stateless ! Evaluate functions and create expressions instead of statements ! More difficult conceptually ! Examples: Scala, Haskell if (value % 2 == 0) { // do something }
  74. Imperative vs. Functional Imperative Programming ! Describes how the program

    operates ! Uses statements to change state of the program ! Conditional statements, loops, inheritance ! Easier initial learning curve ! Examples: C, PHP, Java Functional Programming ! Describes what the program should accomplish ! Ideally stateless ! Evaluate functions and create expressions instead of statements ! More difficult conceptually ! Examples: Scala, Haskell if (value % 2 == 0) { // do something } boolean filter(int value) { return value % 2 == 0; }
  75. History of Imperative Programming ! Old computers utilized vacuum tubes

    and very limited memory ! Programs written as step-by-step instructions ! FORTRAN introduced in 1954. Compiled, variables, complex expressions. ! 60s and 70s: COBOL, BASIC, C ! Object-oriented code grew in popularity in the 1980s. Smalltalk. C++ ! 90s: Perl, Python, Javascript, Ruby, Java
  76. History of Functional Programming ! Based on lambda calculus (Church

    1936) ◦ Study of computation with functions ! Lisp was developed by IBM in the 1950s ◦ LISP = LISt Processor ◦ Still in use today ◦ Only a year younger than FORTRAN ! John Backus gave a 1978 Turing Award lecture on why imperative programming is “bad” and functional programming is “good” ! 80s-00s - Object-Oriented programming dominated based on principles like encapsulation. Academics and theoreticians care about Functional Programming. ! 2010s - JavaScript made passing around functions cool again
  77. Reactive Programming
 1. Data streams
 
 2. Functional programming
 


    3. Asynchronous observers

  78. Reactive Programming
 1. Data streams
 
 2. Functional programming
 


    3. Asynchronous observers

  79. A flow of data objects from one function to the

    next Reactive Programming
 1. Data streams
 
 2. Functional programming
 
 3. Asynchronous observers

  80. Reactive Programming
 1. Data streams
 
 2. Functional programming
 


    3. Asynchronous observers

  81. ! Functions are meant to be pure Reactive Programming
 1.

    Data streams
 
 2. Functional programming
 
 3. Asynchronous observers

  82. ! Functions are meant to be pure ! All functions

    have an input and output data types Reactive Programming
 1. Data streams
 
 2. Functional programming
 
 3. Asynchronous observers

  83. ! Functions are meant to be pure ! All functions

    have an input and output data types ! No external state is modified (no side-effects) Reactive Programming
 1. Data streams
 
 2. Functional programming
 
 3. Asynchronous observers

  84. ! Functions are meant to be pure ! All functions

    have an input and output data types ! No external state is modified (no side-effects) Example:
 add(x, y) -> return x + y Reactive Programming
 1. Data streams
 
 2. Functional programming
 
 3. Asynchronous observers

  85. Reactive Programming
 1. Data streams
 
 2. Functional programming
 


    3. Asynchronous observers

  86. Uses the Observer pattern with Subject data sources that notify

    Observers Reactive Programming
 1. Data streams
 
 2. Functional programming
 
 3. Asynchronous observers

  87. Uses the Observer pattern with Subject data sources that notify

    Observers Errors propagated through the flow of data Reactive Programming
 1. Data streams
 
 2. Functional programming
 
 3. Asynchronous observers

  88. Reactive Programming is NOT

  89. Reactive Programming is NOT ! It's own language ! React,

    ReactJs, ReactNative
  90. RxJava

  91. RxJava ! The Java library for the Reactive Extensions specification

    ◦ This specification is applied to other languages: RxJs, RxSwift, etc. - reactivex.io/languages
  92. RxJava ! The Java library for the Reactive Extensions specification

    ◦ This specification is applied to other languages: RxJs, RxSwift, etc. - reactivex.io/languages ! Helpful due to complicated stream and asynchronous apis
  93. RxJava ! The Java library for the Reactive Extensions specification

    ◦ This specification is applied to other languages: RxJs, RxSwift, etc. - reactivex.io/languages ! Helpful due to complicated stream and asynchronous apis ! Brings functional design to an object-oriented language
  94. RxJava ! The Java library for the Reactive Extensions specification

    ◦ This specification is applied to other languages: RxJs, RxSwift, etc. - reactivex.io/languages ! Helpful due to complicated stream and asynchronous apis ! Brings functional design to an object-oriented language ! Very helpful for mobile development, which often involves asynchronously requesting data from a server, transforming it, and displaying it in the UI
  95. introduction background examples live demo wrap-up

  96. ... to subscribe to data Imperative List<Integer> data = 


    new DataSource().getData(); for (Integer value : data) { System.out.println(value); } Output: 4, 2, 1, 7, 6, ... Data: 4, 2, 1, 7, 6, ...
  97. ... to subscribe to data Imperative List<Integer> data = 


    new DataSource().getData(); for (Integer value : data) { System.out.println(value); } Output: 4, 2, 1, 7, 6, ... Data: 4, 2, 1, 7, 6, ...
  98. ... to subscribe to data Imperative List<Integer> data = 


    new DataSource().getData(); for (Integer value : data) { System.out.println(value); } Output: 4, 2, 1, 7, 6, ... Data: 4, 2, 1, 7, 6, ...
  99. ... to subscribe to data Reactive new DataSource().getDataStream() .subscribe(new Consumer<Integer>()

    { @Override public void accept(Integer value) { System.out.println(value); } }); Imperative List<Integer> data = 
 new DataSource().getData(); for (Integer value : data) { System.out.println(value); } Output: 4, 2, 1, 7, 6, ... Data: 4, 2, 1, 7, 6, ...
  100. ... to subscribe to data Imperative List<Integer> data = 


    new DataSource().getData(); for (Integer value : data) { System.out.println(value); } Reactive new DataSource().getDataStream() .subscribe(new Consumer<Integer>() { @Override public void accept(Integer value) { System.out.println(value); } }); Output: 4, 2, 1, 7, 6, ... Data: 4, 2, 1, 7, 6, ...
  101. ... to subscribe to data Reactive new DataSource().getDataStream() .subscribe(new Consumer<Integer>()

    { @Override public void accept(Integer value) { System.out.println(value); } }); Imperative List<Integer> data = 
 new DataSource().getData(); for (Integer value : data) { System.out.println(value); } Output: 4, 2, 1, 7, 6, ... Data: 4, 2, 1, 7, 6, ...
  102. ... to subscribe to data Reactive new DataSource().getDataStream() .subscribe(new Consumer<Integer>()

    { @Override public void accept(Integer value) { System.out.println(value); } }); Imperative List<Integer> data = 
 new DataSource().getData(); for (Integer value : data) { System.out.println(value); } Output: 4, 2, 1, 7, 6, ... Data: 4, 2, 1, 7, 6, ...
  103. ... to subscribe to data Reactive new DataSource().getDataStream() .subscribe(new Consumer<Integer>()

    { @Override public void accept(Integer value) { System.out.println(value); } }); Imperative List<Integer> data = 
 new DataSource().getData(); for (Integer value : data) { System.out.println(value); } Output: 4, 2, 1, 7, 6, ... Data: 4, 2, 1, 7, 6, ...
  104. ... to subscribe to data Reactive new DataSource().getDataStream() .subscribe(new Consumer<Integer>()

    { @Override public void accept(Integer value) { System.out.println(value); } }); Imperative List<Integer> data = 
 new DataSource().getData(); for (Integer value : data) { System.out.println(value); } Output: 4, 2, 1, 7, 6, ... Data: 4, 2, 1, 7, 6, ...
  105. ... to subscribe to data Reactive new DataSource().getDataStream() .subscribe(
 value

    -> System.out.println(value)
 ); Imperative List<Integer> data = 
 new DataSource().getData(); for (Integer value : data) { System.out.println(value); } Output: 4, 2, 1, 7, 6, ... Data: 4, 2, 1, 7, 6, ...
  106. ... to subscribe to data Reactive new DataSource().getDataStream() .subscribe( value

    -> System.out.println(value) ); Imperative List<Integer> data = 
 new DataSource().getData(); for (Integer value : data) { System.out.println(value); } Output: 4, 2, 1, 7, 6, ... Data: 4, 2, 1, 7, 6, ...
  107. ... to subscribe to data Reactive new DataSource().getDataStream() .subscribe( value

    -> updateUI(value) ); Imperative List<Integer> data = 
 new DataSource().getData(); for (Integer value : data) { updateUI(value); }
  108. ... to subscribe to data Reactive new DataSource().getDataStream() .subscribe( value

    -> saveToDatabase(value) ); Imperative List<Integer> data = 
 new DataSource().getData(); for (Integer value : data) { saveToDatabase(value); }
  109. ... to subscribe to data changes

  110. ... to subscribe to data changes Imperative ScheduledExecutorService scheduler =

    // initialize Runnable runner = new Runnable() { public void run() { List<Integer> data = new DataSource().getData(); for (Integer value : data) { System.out.println(value); } } }; ScheduledFuture<?> future = // initialize scheduler.schedule(new Runnable() { public void run() { future.cancel(/* mayInterruptIfRunning */ true); } }, /* delay */ 0, TimeUnit.SECONDS);
  111. ... to subscribe to data changes Imperative ScheduledExecutorService scheduler =

    // initialize Runnable runner = new Runnable() { public void run() { List<Integer> data = new DataSource().getData(); for (Integer value : data) { System.out.println(value); } } }; ScheduledFuture<?> future = // initialize scheduler.schedule(new Runnable() { public void run() { future.cancel(/* mayInterruptIfRunning */ true); } }, /* delay */ 0, TimeUnit.SECONDS); ???
  112. ... to subscribe to data changes Imperative ScheduledExecutorService scheduler =

    // initialize Runnable runner = new Runnable() { public void run() { List<Integer> data = new DataSource().getData(); for (Integer value : data) { System.out.println(value); } } }; ScheduledFuture<?> future = // initialize scheduler.schedule(new Runnable() { public void run() { future.cancel(/* mayInterruptIfRunning */ true); } }, /* delay */ 0, TimeUnit.SECONDS); Reactive new DataSource().getDataStream() .subscribe( value -> System.out.println(value) );
  113. ... to filter our data

  114. ... to filter our data Imperative List<Integer> data = 


    new DataSource().getData(); for (Integer value : data) { if (value % 2 == 0) { System.out.println(value); } } Output: 4, 2, 6, ... Data: 4, 2, 1, 7, 6, ...
  115. ... to filter our data Imperative List<Integer> data = 


    new DataSource().getData(); for (Integer value : data) { if (value % 2 == 0) { System.out.println(value); } } Output: 4, 2, 6, ... Data: 4, 2, 1, 7, 6, ...
  116. ... to filter our data http://reactivex.io/documentation/operators/filter

  117. ... to filter our data Reactive new DataSource().getDataStream() .filter(value ->

    value % 2 == 0) .subscribe(
 result -> System.out.println(result)
 ); Imperative List<Integer> data = 
 new DataSource().getData(); for (Integer value : data) { if (value % 2 == 0) { System.out.println(value); } } Output: 4, 2, 6, ... Data: 4, 2, 1, 7, 6, ...
  118. ... to filter our data Reactive new DataSource().getDataStream() .filter(value ->

    value % 2 == 0) .subscribe(
 result -> System.out.println(result)
 ); Imperative List<Integer> data = 
 new DataSource().getData(); for (Integer value : data) { if (value % 2 == 0) { System.out.println(value); } } Output: 4, 2, 6, ... Data: 4, 2, 1, 7, 6, ...
  119. … to map our data Output: 8, 4, 2, 14,

    12, ... Data: 4, 2, 1, 7, 6, ...
  120. … to map our data Imperative List<Integer> data = new

    DataSource().getData(); for (Integer value : data) { int result = value * 2; System.out.println(result); } Output: 8, 4, 2, 14, 12, ... Data: 4, 2, 1, 7, 6, ...
  121. ... to map our data Imperative List<Integer> data = new

    DataSource().getData(); for (Integer value : data) { int result = value * 2; System.out.println(result); } Output: 8, 4, 2, 14, 12, ... Data: 4, 2, 1, 7, 6, ...
  122. ... to map our data http://reactivex.io/documentation/operators/map

  123. ... to map our data Reactive new DataSource().getDataStream() .map(value ->

    value * 2) .subscribe( result -> System.out.println(result) ); Imperative List<Integer> data = new DataSource().getData(); for (Integer value : data) { int result = value * 2; System.out.println(result); } Output: 8, 4, 2, 14, 12, ... Data: 4, 2, 1, 7, 6, ...
  124. ... to map our data Reactive new DataSource().getDataStream() .map(value ->

    value * 2) .subscribe( result -> System.out.println(result) ); Imperative List<Integer> data = new DataSource().getData(); for (Integer value : data) { int result = value * 2; System.out.println(result); } Output: 8, 4, 2, 14, 12, ... Data: 4, 2, 1, 7, 6, ...
  125. ... to group our data

  126. ... to group our data List<Integer> data = new DataSource().getData();

    Map<String, List<Integer>> result = new HashMap<>(); String evenKey = "EVEN"; String oddKey = "ODD"; for (Integer value : data) { String key; if (value % 2 == 0) { key = evenKey; } else { key = oddKey; } result.putIfAbsent( key, new ArrayList<>()); result.get(key).add(datum); } System.out.println(result); Output: {EVEN=[4, 2, 6], ODD=[1, 7]} Data: 4, 2, 1, 7, 6
  127. ... to group our data http://reactivex.io/documentation/operators/groupby

  128. ... to group our data new DataSource().getDataStream() .groupBy( value ->

    (value % 2) == 0 ? "EVEN" : "ODD" ) .collectInto( // put our groups into a hashmap // this is actually still a little messy ) .subscribe( resultMap -> System.out.println(resultMap) ); Output: {EVEN=[4, 2, 6], ODD=[1, 7]} Data: 4, 2, 1, 7, 6
  129. ... to group our data new DataSource().getDataStream() .groupBy( value ->

    (value % 2) == 0 ? "EVEN" : "ODD" ) .collectInto( // put our groups into a hashmap // this is actually still a little messy ) .subscribe( resultMap -> System.out.println(resultMap) ); List<Integer> data = new DataSource().getData(); Map<String, List<Integer>> result = new HashMap<>(); String evenKey = "EVEN"; String oddKey = "ODD"; for (Integer value : data) { String key; if (value % 2 == 0) { key = evenKey; } else { key = oddKey; } result.putIfAbsent( key, new ArrayList<>()); result.get(key).add(datum); } System.out.println(result); Output: {EVEN=[4, 2, 6], ODD=[1, 7]} Data: 4, 2, 1, 7, 6
  130. So many more operators ! Transforming ! Buffer ! Scan

    ! Filtering ! Debounce ! Distinct ! First ! Last ! Take ! Min ! Combining ! Join ! Merge ! Zip ! Math ! Average ! Concat ! Max
  131. Some operations can get complicated http://reactivex.io/documentation/operators/join

  132. introduction background examples live demo wrap-up

  133. introduction background examples live demo wrap-up

  134. Reactive Programming 1. Data streams
 2. Functional Programming
 3. Asynchronous

    observers
  135. Thanks!