|
1 | 1 | # PART 2 - Sequence basics |
2 | 2 |
|
3 | | -Now that you understand what Rx is in general, it is time to start creating and manipulating sequences. The original implementation of manipulating sequences was based on C#'s LINQ, which in turn was inspired from functional programming. Knowledge about either isn't necessary, but it would make the learning process a lot easier for the reader. Following the original www.introtorx.com, we too will divide operations into themes that generally go from the simpler to the more advanced. Most Rx operators manipulate existing sequences. But first, we will see how to create an `Observable` to begin with. |
| 3 | +Now that you understand what Rx is in general, it is time to start creating and manipulating sequences. The original implementation of manipulating sequences was based on C#'s [LINQ](https://en.wikipedia.org/wiki/Language_Integrated_Query), which in turn was inspired from functional programming. Knowledge about either isn't necessary, but it would make the learning process a lot easier for the reader. Following the original www.introtorx.com, we too will divide operations into themes that generally go from the simpler to the more advanced. Most Rx operators manipulate existing sequences. But first, we will see how to create an `Observable` to begin with. |
4 | 4 |
|
5 | 5 | # Creating a sequence |
6 | 6 |
|
7 | | -In previous examples we used `Subject`s and manually pushed values into them to create an sequence. We used that sequence to demonstrate some key concepts and the first and most important Rx method, `subscribe`. In most cases, subjects are not the best way to create a new `Observable`. We will now see tidier ways to create observable sequences. |
| 7 | +In previous examples we used `Subject`s and manually pushed values into them to create a sequence. We used that sequence to demonstrate some key concepts and the first and most important Rx method, `subscribe`. In most cases, subjects are not the best way to create a new `Observable`. We will now see tidier ways to create observable sequences. |
8 | 8 |
|
9 | 9 | ## Simple factory methods |
10 | 10 |
|
@@ -79,7 +79,7 @@ Error: java.lang.Exception: Oops |
79 | 79 |
|
80 | 80 | ### Observable.defer |
81 | 81 |
|
82 | | -`defer` doesn't define a new kind of observable, but allows you to declare how a source observable should be created every time a subscriber arrives. Consider how you would create an observable that returns the current time and terminates. You are emitting a single value, so it sounds like a case for `just`. |
| 82 | +`defer` doesn't define a new kind of observable, but allows you to declare how an observable should be created every time a subscriber arrives. Consider how you would create an observable that returns the current time and terminates. You are emitting a single value, so it sounds like a case for `just`. |
83 | 83 |
|
84 | 84 | ```java |
85 | 85 | Observable<Long> now = Observable.just(System.currentTimeMillis()); |
@@ -118,7 +118,7 @@ now.subscribe(System.out::println); |
118 | 118 | static <T> Observable<T> create(Observable.OnSubscribe<T> f) |
119 | 119 | ``` |
120 | 120 |
|
121 | | -The `Observable.OnSubscribe<T>` is simpler than it looks. It is basically a function that takes an `Subscriber<T>` for type `T`. Inside it we can manually determine the events that are pushed to the subscriber. |
| 121 | +The `Observable.OnSubscribe<T>` is simpler than it looks. It is basically a function that takes a `Subscriber<T>` for type `T`. Inside it we can manually determine the events that are pushed to the subscriber. |
122 | 122 |
|
123 | 123 | ```java |
124 | 124 | Observable<String> values = Observable.create(o -> { |
@@ -228,7 +228,7 @@ The example above waits 2 seconds, then starts counting every 1 second. |
228 | 228 |
|
229 | 229 | There are well established tools for dealing with sequences, collections and asychronous events, which may not be directly compatible with Rx. Here we will discuss ways to turn their output into input for your Rx code. |
230 | 230 |
|
231 | | -If you are using an asynchonous tool that uses event handlers, like JavaFX, you can use `Observable.create` to turn the streams into an observable |
| 231 | +If you are using an asynchronous tool that uses event handlers, like JavaFX, you can use `Observable.create` to turn the streams into an observable |
232 | 232 |
|
233 | 233 | ```java |
234 | 234 | Observable<ActionEvent> events = Observable.create(o -> { |
@@ -296,7 +296,7 @@ Received: 3 |
296 | 296 | Completed |
297 | 297 | ``` |
298 | 298 |
|
299 | | -`Observable` is not interchangeable with `Iterable` or `Stream`. `Observable`s are push-based. i.e. the call to `onNext` causes the stack of handlers to execute all the way to the final subscriber method (unless specified otherwise). The other model are pull-based, which means that values are requested as soon as possible and execution blocks until the result is returned. |
| 299 | +`Observable` is not interchangeable with `Iterable` or `Stream`. `Observable`s are push-based, i.e., the call to `onNext` causes the stack of handlers to execute all the way to the final subscriber method (unless specified otherwise). The other models are pull-based, which means that values are requested as soon as possible and execution blocks until the result is returned. |
300 | 300 |
|
301 | 301 | #### Continue reading |
302 | 302 |
|
|
0 commit comments