Skip to content

Commit 772f88f

Browse files
committed
Merge remote-tracking branch 'origin/master' into Unpublished-content
2 parents de0b592 + fb73fa6 commit 772f88f

13 files changed

+54
-55
lines changed

Part 1 - Getting Started/1. Why Rx.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# PART 1 - Getting starter
1+
# PART 1 - Getting started
22

33
## Why Rx
44

Part 1 - Getting Started/2. Key types.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ interface Observer<T> {
4040

4141
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`.
4242

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.
4444

4545

4646
## Implementing Observable and Observer
@@ -132,9 +132,8 @@ Late: 3
132132
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`
133133

134134
```java
135-
ReplaySubject<Integer> s = ReplaySubject.createWithTime(
136-
150, TimeUnit.MILLISECONDS,
137-
Schedulers.immediate());
135+
ReplaySubject<Integer> s = ReplaySubject.createWithTime(150, TimeUnit.MILLISECONDS,
136+
Schedulers.immediate());
138137
s.onNext(0);
139138
Thread.sleep(100);
140139
s.onNext(1);

Part 1 - Getting Started/3. Lifetime management.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Lifetime management
22

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.
44

55
## Subscribing
66

Part 2 - Sequence Basics/1. Creating a sequence.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# PART 2 - Sequence basics
22

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.
44

55
# Creating a sequence
66

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.
88

99
## Simple factory methods
1010

@@ -79,7 +79,7 @@ Error: java.lang.Exception: Oops
7979

8080
### Observable.defer
8181

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`.
8383

8484
```java
8585
Observable<Long> now = Observable.just(System.currentTimeMillis());
@@ -118,7 +118,7 @@ now.subscribe(System.out::println);
118118
static <T> Observable<T> create(Observable.OnSubscribe<T> f)
119119
```
120120

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.
122122

123123
```java
124124
Observable<String> values = Observable.create(o -> {
@@ -228,7 +228,7 @@ The example above waits 2 seconds, then starts counting every 1 second.
228228

229229
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.
230230

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
232232

233233
```java
234234
Observable<ActionEvent> events = Observable.create(o -> {
@@ -296,7 +296,7 @@ Received: 3
296296
Completed
297297
```
298298

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.
300300

301301
#### Continue reading
302302

Part 2 - Sequence Basics/2. Reducing a sequence.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Most of the operators here will be familiar to anyone who has worked with Java's
66

77
### Marble diagrams
88

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.
1010

1111
![](https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/legend.png)
1212

@@ -111,7 +111,7 @@ Third
111111
Completed
112112
```
113113

114-
"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".
115115

116116
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.
117117

@@ -182,7 +182,7 @@ Completed
182182

183183
## ignoreElements
184184

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`.
186186

187187
```java
188188
Observable<Integer> values = Observable.range(0, 10);
@@ -232,7 +232,7 @@ Subscription first2 = values
232232
Completed
233233
```
234234

235-
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.
236236

237237
`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.
238238

@@ -310,7 +310,7 @@ Completed
310310

311311
## skipWhile and takeWhile
312312

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`
314314

315315
```java
316316
Observable<T> takeWhile(Func1<? super T,java.lang.Boolean> predicate)
@@ -414,7 +414,7 @@ Completed
414414

415415
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.
416416

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.
418418

419419
```java
420420
Observable<Long> values = Observable.interval(100,TimeUnit.MILLISECONDS);

Part 2 - Sequence Basics/3. Inspection.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ All: Completed
6767
Completed
6868
```
6969

70-
If the source observable emits an error, then `all` becomes irrelavant and the error passes through, terminating the sequence.
70+
If the source observable emits an error, then `all` becomes irrelevant and the error passes through, terminating the sequence.
7171

7272
```java
7373
Observable<Integer> values = Observable.create(o -> {
@@ -172,7 +172,7 @@ false
172172
Completed
173173
```
174174

175-
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.
176176

177177
## contains
178178

@@ -202,7 +202,7 @@ If we had used `contains(4)` where we used `contains(4L)`, nothing would be prin
202202

203203
## defaultIfEmpty
204204

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.
206206

207207
![](https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/defaultIfEmpty.png)
208208

@@ -310,7 +310,7 @@ true
310310
Completed
311311
```
312312

313-
If swap the operator for the one that is commented out (i.e the one that uses the the standard `Object.equals`), the result would be `false`.
313+
If we swap the operator for the one that is commented out, i.e, the one using the standard `Object.equals`, the result would be `false`.
314314

315315
Failing is not part of the comparison. As soon as either sequence fails, the resulting observable forwards the error.
316316

Part 2 - Sequence Basics/4. Aggregation.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ Single1: 5
103103
Single1: Completed
104104
```
105105

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`
107107

108108
## Custom aggregators
109109

110110
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.
111111

112112
### reduce
113113

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.
115115

116116
```java
117117
public final Observable<T> reduce(Func2<T,T,T> accumulator)
@@ -279,7 +279,7 @@ values
279279
[10, 11, 12, 13, 14]
280280
```
281281

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.
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.
283283

284284
#### toList
285285

@@ -314,7 +314,7 @@ values
314314
.toSortedList((i1,i2) -> i2 - i1)
315315
.subscribe(v -> System.out.println(v));
316316
```
317-
[Output]((/tests/java/itrx/chapter2/aggregation/ToCollectionExample.java)
317+
[Output](/tests/java/itrx/chapter2/aggregation/ToCollectionExample.java)
318318
```
319319
[14, 13, 12, 11, 10]
320320
```
@@ -533,7 +533,7 @@ Nested observables may be confusing at first, but they are a powerful construct
533533
* Partitions of Data
534534
* 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.
535535
* 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.
537537
* Financial data streams
538538
* New markets or instruments may open and close during the day. These would then stream price information and could complete when the market closes.
539539
* Chat Room
@@ -543,7 +543,7 @@ Nested observables may be confusing at first, but they are a powerful construct
543543

544544
### nest
545545

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.
547547

548548
![](https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/nest.png)
549549

Part 2 - Sequence Basics/5. Transformation of sequences.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Map: 2
115115
Map: Error: java.lang.ClassCastException: Cannot cast java.lang.String to java.lang.Integer
116116
```
117117

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.
119119

120120
```java
121121
Observable<Object> values = Observable.just(0, 1, "2", 3);
@@ -182,7 +182,7 @@ TimeInterval: TimeInterval [intervalInMilliseconds=100, value=2]
182182
TimeInterval: Completed
183183
```
184184

185-
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.
186186

187187
### materialize and dematerialize
188188

0 commit comments

Comments
 (0)