You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Part 1 - Getting Started/2. Key types.md
+3-4Lines changed: 3 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,7 +40,7 @@ interface Observer<T> {
40
40
41
41
Those three methods are the behaviour that is executed every time the observable pushes a value. The observer will have its `onNext` called zero or more times, optionally followed by an `onCompleted` or an `onError`. No calls happen after a call to `onError` or `onCompleted`.
42
42
43
-
When developing Rx code, you'll see a lot of `Observable`, but not so much of `Observer`. While it is important to understand the `Observer`, there are shorthands that that remove the need to instantiate it yourself.
43
+
When developing Rx code, you'll see a lot of `Observable`, but not so much of `Observer`. While it is important to understand the `Observer`, there are shorthands that remove the need to instantiate it yourself.
44
44
45
45
46
46
## Implementing Observable and Observer
@@ -132,9 +132,8 @@ Late: 3
132
132
Our late subscriber now missed the first value, which fell off the buffer of size 2. Similarily, old values fall off the buffer as time passes, when the subject is created with `createWithTime`
133
133
134
134
```java
135
-
ReplaySubject<Integer> s =ReplaySubject.createWithTime(
136
-
150, TimeUnit.MILLISECONDS,
137
-
Schedulers.immediate());
135
+
ReplaySubject<Integer> s =ReplaySubject.createWithTime(150, TimeUnit.MILLISECONDS,
Copy file name to clipboardExpand all lines: Part 1 - Getting Started/3. Lifetime management.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Lifetime management
2
2
3
-
The idea behind Rx that it is unknown *when* a sequence emits values or terminates, but you still have control over when you begin and stop accepting values. Subscriptions may be linked to allocated resources that you will want to release at the end of a sequence. Rx provides control over your subscriptions to enable you to do that.
3
+
The idea behind Rx is that it is unknown *when* a sequence emits values or terminates, but you still have control over when you begin and stop accepting values. Subscriptions may be linked to allocated resources that you will want to release at the end of a sequence. Rx provides control over your subscriptions to enable you to do that.
Copy file name to clipboardExpand all lines: Part 2 - Sequence Basics/1. Creating a sequence.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
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.
`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());
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.
@@ -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
`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.
Copy file name to clipboardExpand all lines: Part 2 - Sequence Basics/2. Reducing a sequence.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ Most of the operators here will be familiar to anyone who has worked with Java's
6
6
7
7
### Marble diagrams
8
8
9
-
This is an appropriate time to introduce to concept of marble diagrams. It is a popular way of explaining the operators in Rx, because of their intuitive and graphical nature. They are present a lot in the documetation of RxJava and it only makes sense that we take advantage of their explanatory nature. The format is mostly self-explanatory: time flows left to right, shapes represent values, a slash is a onCompletion, an X is an error. The operator is applied to the top sequence and the result is the sequence below.
9
+
This is an appropriate time to introduce to concept of marble diagrams. It is a popular way of explaining the operators in Rx, because of their intuitive and graphical nature. They are present a lot in the documentation of RxJava and it only makes sense that we take advantage of their explanatory nature. The format is mostly self-explanatory: time flows left to right, shapes represent values, a slash is a onCompletion, an X is an error. The operator is applied to the top sequence and the result is the sequence below.
"Fourth" and "Fifth" were filtered out because their is is 'F' and that has already appeared in "First".
114
+
"Fourth" and "Fifth" were filtered out because their first character is 'F' and that has already appeared in "First".
115
115
116
116
An experienced programmer already knows that this operator maintains a set internally with every unique value that passes through the observable and checks every new value against it. While Rx operators neatly hide these things, you should still be aware that an Rx operator can have a significant cost and consider what you are using it on.
117
117
@@ -182,7 +182,7 @@ Completed
182
182
183
183
## ignoreElements
184
184
185
-
`ignoreElements` will ignore every value, but lets though`onCompleted` and `onError`.
185
+
`ignoreElements` will ignore every value, but lets pass through`onCompleted` and `onError`.
Users of Java 8 streams will be know the `take` operator as `limit`. The `limit` operator exists in Rx too, for symmetry purposes. It is an alias of `take`, but it lacks the richer overloads that we will soon see.
235
+
Users of Java 8 streams should know the `take` operator as `limit`. The `limit` operator exists in Rx too, for symmetry purposes. It is an alias of `take`, but it lacks the richer overloads that we will soon see.
236
236
237
237
`take` completes as soon as the n-th item is available. If an error occurs, the error will be forwarded, but not if it occurs after the cutting point. `take` doesn't care what happens in the observable after the n-th item.
238
238
@@ -310,7 +310,7 @@ Completed
310
310
311
311
## skipWhile and takeWhile
312
312
313
-
`take` and `skip` work with predefined indices. If you want to "discover" the cutoff point as the values come, `takeWhile` and `shipWhile` will use a predicate instead. `takeWhile` takes items while a predicate function returns `true`
313
+
`take` and `skip` work with predefined indices. If you want to "discover" the cutoff point as the values come, `takeWhile` and `skipWhile` will use a predicate instead. `takeWhile` takes items while a predicate function returns `true`
314
314
315
315
```java
316
316
Observable<T> takeWhile(Func1<? super T,java.lang.Boolean> predicate)
@@ -414,7 +414,7 @@ Completed
414
414
415
415
As you may remember, `timer` here will wait 250ms and emit one event. This signals `takeUntil` to stop the sequence. Note that the signal can be of any type, since the actual value is not used.
416
416
417
-
Once again `skipUntil` works by the same rules and returns the other half of the observable. Values are ignored until the signal comes to start letting values through.
417
+
Once again `skipUntil` works by the same rules and returns the other half of the observable. Values are ignored until the signal comes to start letting values pass through.
Falsehood is established as soon as the first value is emitted. True will can be returned once the source observable has terminated.
175
+
Falsehood is established as soon as the first value is emitted. `true` will be returned once the source observable has terminated.
176
176
177
177
## contains
178
178
@@ -202,7 +202,7 @@ If we had used `contains(4)` where we used `contains(4L)`, nothing would be prin
202
202
203
203
## defaultIfEmpty
204
204
205
-
If an empty sequence would cause you problems, rather than checking with `isEmpty` and handling the case, you can force an obserable to emit a value on completion if didn't emit anything before completing.
205
+
If an empty sequence would cause you problems, rather than checking with `isEmpty` and handling the case, you can force an observable to emit a value on completion if it didn't emit anything before completing.
Copy file name to clipboardExpand all lines: Part 2 - Sequence Basics/4. Aggregation.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -103,15 +103,15 @@ Single1: 5
103
103
Single1: Completed
104
104
```
105
105
106
-
Like in with previous methods, you can have a default value with `singleOrDefault`
106
+
Like in the previous methods, you can have a default value with `singleOrDefault`
107
107
108
108
## Custom aggregators
109
109
110
110
The methods we saw on this chapter so far don't seem that different from the ones in previous chapters. We will now see two very powerful methods that will greatly expand what we can do with an observable. Many of the methods we've seen so far can be implemented using those.
111
111
112
112
### reduce
113
113
114
-
You may have heard of `reduce` from MapReduce. Alternatively, you might have met it under the names "aggregate", "accumulate" or "fold". The general idea is that you produce a single value out of many by combining them two at a time. It its most basic overload, all you need is a function that combines two values into one.
114
+
You may have heard of `reduce` from [MapReduce] (https://en.wikipedia.org/wiki/MapReduce). Alternatively, you might have met it under the names "aggregate", "accumulate" or "fold". The general idea is that you produce a single value out of many by combining them two at a time. In its most basic overload, all you need is a function that combines two values into one.
Usually, you won't have to collect values manually. Rxjava offers a variety of operators for collecting your sequence into a container. Those aggregators return an observable that will emit the corresponding collection when it is ready, just like what we did here. We will see such aggregators next.
282
+
Usually, you won't have to collect values manually. RxJava offers a variety of operators for collecting your sequence into a container. Those aggregators return an observable that will emit the corresponding collection when it is ready, just like what we did here. We will see such aggregators next.
@@ -533,7 +533,7 @@ Nested observables may be confusing at first, but they are a powerful construct
533
533
* Partitions of Data
534
534
* You may partition data from a single source so that it can easily be filtered and shared to many sources. Partitioning data may also be useful for aggregates as we have seen. This is commonly done with the `groupBy` operator.
535
535
* Online Game servers
536
-
* Consider a sequence of servers. New values represent a server coming online. The value itself is a sequence of latency values allowing the consumer to see real time information of quantity and quality of servers available. If a server went down then the inner sequence can signify that by completing.
536
+
* Consider a sequence of servers. New values represent a server coming online. The value itself is a sequence of latency values allowing the consumer to see real time information of quantity and quality of servers available. If a server went down then the inner sequence can signal that by completing.
537
537
* Financial data streams
538
538
* New markets or instruments may open and close during the day. These would then stream price information and could complete when the market closes.
539
539
* Chat Room
@@ -543,7 +543,7 @@ Nested observables may be confusing at first, but they are a powerful construct
543
543
544
544
### nest
545
545
546
-
When dealing with nested observables, the `nest` operator becomes useful. It allows you to turn a non-nested observable into a nested observable. `nest` takes a source observable and returns an observable that will the source observable and then terminate.
546
+
When dealing with nested observables, the `nest` operator becomes useful. It allows you to turn a non-nested observable into a nested observable. `nest` takes a source observable and returns an observable that will be the source observable and then terminate.
Copy file name to clipboardExpand all lines: Part 2 - Sequence Basics/5. Transformation of sequences.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -115,7 +115,7 @@ Map: 2
115
115
Map: Error: java.lang.ClassCastException: Cannot cast java.lang.String to java.lang.Integer
116
116
```
117
117
118
-
If you would rather have such cases ignored, you can you the `ofType` method. This will filter our items that cannot be cast and then cast the sequence to the desired type.
118
+
If you would rather have such cases ignored, you can use the `ofType` method. This will filter our items that cannot be cast and then cast the sequence to the desired type.
The information captured by `timestamp` and `timeInterval` is very useful for logging and debugging. It is Rx's way of aquiring information about the asynchronicity of sequences.
185
+
The information captured by `timestamp` and `timeInterval` is very useful for logging and debugging. It is Rx's way of acquiring information about the asynchronicity of sequences.
0 commit comments