Skip to content

Commit ae26e15

Browse files
committed
Linked to examples
1 parent 61c9785 commit ae26e15

File tree

1 file changed

+35
-15
lines changed

1 file changed

+35
-15
lines changed

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

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ values
4848
.map(i -> i + 3)
4949
.subscribe(new PrintSubscriber("Map"));
5050
```
51-
Output
51+
[Output](/tests/java/itrx/chapter2/transforming/MapExample.java)
5252
```
5353
Map: 3
5454
Map: 4
@@ -67,7 +67,7 @@ Observable<Integer> values =
6767
values.subscribe(new PrintSubscriber("Map"));
6868
```
6969

70-
Output
70+
[Output](/tests/java/itrx/chapter2/transforming/MapExample.java)
7171
```
7272
Map: 0
7373
Map: 1
@@ -89,7 +89,7 @@ values
8989
.cast(Integer.class)
9090
.subscribe(new PrintSubscriber("Map"));
9191
```
92-
Output
92+
[Output](/tests/java/itrx/chapter2/transforming/CastTypeOfExample.java)
9393
```
9494
Map: 0
9595
Map: 1
@@ -107,7 +107,7 @@ values
107107
.cast(Integer.class)
108108
.subscribe(new PrintSubscriber("Map"));
109109
```
110-
Output
110+
[Output](/tests/java/itrx/chapter2/transforming/CastTypeOfExample.java)
111111
```
112112
Map: 0
113113
Map: 1
@@ -124,7 +124,7 @@ values
124124
.ofType(Integer.class)
125125
.subscribe(new PrintSubscriber("Map"));
126126
```
127-
Output
127+
[Output](/tests/java/itrx/chapter2/transforming/CastTypeOfExample.java)
128128
```
129129
Map: 0
130130
Map: 1
@@ -149,7 +149,7 @@ values.take(3)
149149
.timestamp()
150150
.subscribe(new PrintSubscriber("Timestamp"));
151151
```
152-
Output
152+
[Output](/tests/java/itrx/chapter2/transforming/TimestampTimeIntervalExample.java)
153153
```
154154
Timestamp: Timestamped(timestampMillis = 1428611094943, value = 0)
155155
Timestamp: Timestamped(timestampMillis = 1428611095037, value = 1)
@@ -174,7 +174,7 @@ values.take(3)
174174
.timeInterval()
175175
.subscribe(new PrintSubscriber("TimeInterval"));
176176
```
177-
Output
177+
[Output](/tests/java/itrx/chapter2/transforming/TimestampTimeIntervalExample.java)
178178
```
179179
TimeInterval: TimeInterval [intervalInMilliseconds=131, value=0]
180180
TimeInterval: TimeInterval [intervalInMilliseconds=75, value=1]
@@ -203,7 +203,7 @@ values.take(3)
203203
.materialize()
204204
.subscribe(new PrintSubscriber("Materialize"));
205205
```
206-
Output
206+
[Output](/tests/java/itrx/chapter2/transforming/MaterializeExample.java)
207207
```
208208
Materialize: [rx.Notification@a4c802e9 OnNext 0]
209209
Materialize: [rx.Notification@a4c802ea OnNext 1]
@@ -236,7 +236,7 @@ values
236236
.flatMap(i -> Observable.range(0,i))
237237
.subscribe(new PrintSubscriber("flatMap"));
238238
```
239-
Output
239+
[Output](/tests/java/itrx/chapter2/transforming/FlatMapExample.java)
240240
```
241241
flatMap: 0
242242
flatMap: 1
@@ -252,7 +252,7 @@ values
252252
.flatMap(i -> Observable.range(0,i))
253253
.subscribe(new PrintSubscriber("flatMap"));
254254
```
255-
Output
255+
[Output](/tests/java/itrx/chapter2/transforming/FlatMapExample.java)
256256
```
257257
flatMap: 0
258258
flatMap: 0
@@ -290,6 +290,17 @@ values
290290
})
291291
.subscribe(new PrintSubscriber("flatMap"));
292292
```
293+
[Output](/tests/java/itrx/chapter2/transforming/FlatMapExample.java)
294+
```
295+
flatMap: A
296+
flatMap: B
297+
flatMap: C
298+
...
299+
flatMap: X
300+
flatMap: Y
301+
flatMap: Z
302+
flatMap: Completed
303+
```
293304

294305
This example results in the entire alphabet being printed without errors, even though the initial range exceeds that of the alphabet.
295306

@@ -307,7 +318,7 @@ Observable.just(100, 150)
307318

308319
We started with the values 100 and 150, which we used as the interval period for the asynchronous observables created in `flatMap`. Since `interval` emits the numbers 1,2,3... in both cases, to better distinguish the two observables, we replaced those values with interval time that each observable operates on.
309320

310-
Output
321+
[Output](/tests/java/itrx/chapter2/transforming/FlatMapExample.java)
311322
```
312323
flatMap: 100
313324
flatMap: 150
@@ -339,7 +350,7 @@ Observable.just(100, 150)
339350
System.out::println,
340351
() -> System.out.println("Completed"));
341352
```
342-
Output
353+
[Output](/tests/java/itrx/chapter2/transforming/ConcatMapExample.java)
343354
```
344355
100
345356
100
@@ -372,7 +383,7 @@ Observable.range(1, 3)
372383
.flatMapIterable(i -> range(1, i))
373384
.subscribe(System.out::println);
374385
```
375-
Output
386+
[Output](/tests/java/itrx/chapter2/transforming/FlatMapIterableExample.java)
376387
```
377388
1
378389
1
@@ -384,7 +395,7 @@ Output
384395

385396
As expected, the 3 iterables that we created are flattened in a single observable sequence.
386397

387-
As an Rx developer, you are advised to present your data as observable sequences and avoid mixing observables with iterables. However, when your data is already in the format of a collection, e.g. because standard Java operations returned them like that, it can be simpler or faster to just use them as they are without converting them first. `flatMapIterable` also eliminates the need to make a choice about interleaving or not: `flatMapIterable` doesn't interleave, just like you would expect from a synchronous flatMap.
398+
As an Rx developer, you are advised to present your data as observable sequences and avoid mixing observables with iterables. However, when your data is already in the format of a collection, e.g. because standard Java operations returned them like that, it can be simpler or faster to just use them as they are without converting them first. `flatMapIterable` also eliminates the need to make a choice about interleaving or not: `flatMapIterable` doesn't interleave, just like you would expect from a synchronous `flatMap`.
388399

389400
There is a second overload to `flatMapIterable` that allows you to combine every value in the iterable with the value that produced the iterable.
390401

@@ -395,7 +406,7 @@ Observable.range(1, 3)
395406
(ori, rv) -> ori * (Integer) rv)
396407
.subscribe(System.out::println);
397408
```
398-
Output
409+
[Output](/tests/java/itrx/chapter2/transforming/FlatMapIterableExample.java)
399410
```
400411
1
401412
2
@@ -461,6 +472,15 @@ Observable.range(1, 3)
461472
(ori, rv) -> ori * (Integer) rv)
462473
.subscribe(System.out::println);
463474
```
475+
[Output](/tests/java/itrx/chapter2/transforming/FlatMapIterableExample.java)
476+
```
477+
1
478+
2
479+
4
480+
3
481+
6
482+
9
483+
```
464484

465485

466486
#### Continue reading

0 commit comments

Comments
 (0)