This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const pokemonSubscription = pokemon$.subscribe(pokemon => { | |
// Do something with pokemon | |
}); | |
const trainerSubscription = trainer$.subscribe(trainer => { | |
// Do something with trainer | |
}); | |
const numberSubscription = number$.subscribe(number => { | |
// Do something with number |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const trainerSubscription = trainer$.subscribe(trainer => { | |
// Do something with trainer | |
}); | |
const pokemonSubscription = pokemon$.subscribe(pokemon => { | |
// Do something with pokemon | |
}); | |
const numberSubscription = number$.subscribe(number => { | |
// Do something with number |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const stop$ = new Subject<void>(); | |
trainer$ | |
.pipe(takeUntil(stop$)).subscribe(trainer => { | |
// Do something with trainer | |
}); | |
pokemon$ | |
.pipe(takeUntil(stop$)).subscribe(pokemon => { | |
// Do something with pokemon |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pokemon$ = http.get(/* make an http request here*/); | |
/*Every time we subscribe to pokemon$, an http request will be made*/ | |
pokemon$ | |
.pipe( | |
flatMap(pokemon => pokemon), | |
filter(({ type }) => type === "Fire") | |
) | |
.subscribe(pokemon => { | |
// Do something with pokemon |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pokemon$.subscribe((pokemon: Pokemon) => { | |
if (pokemon.type === "Water") { | |
return; | |
} | |
const pokemonStats = getStats(pokemon); | |
logStats(pokemonStats); | |
saveToPokedex(pokemonStats); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pokemon$ | |
.pipe( | |
filter(({ type }) => type !== "Water"), | |
map(pokemon => getStats(pokemon)), | |
tap(stats => logStats(stats)) | |
) | |
.subscribe(stats => saveToPokedex(stats)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> data("mtcars") | |
> mtcars | |
mpg cyl disp hp drat wt qsec vs am gear carb | |
Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4 | |
Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4 | |
Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1 | |
Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1 | |
Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2 | |
Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1 | |
Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> table(mtcars$gear) | |
3 4 5 | |
15 12 5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> mtcars$cyl | |
[1] 6 6 4 6 8 6 8 4 4 6 6 8 8 8 8 8 8 4 4 4 4 8 8 8 8 4 4 4 8 6 8 4 | |
> table(mtcars$cyl) | |
4 6 8 | |
11 7 14 |