Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Created June 20, 2018 15:05
Show Gist options
  • Save ajcrites/6e466769a8adcda53b63f88d2b9fa1d8 to your computer and use it in GitHub Desktop.
Save ajcrites/6e466769a8adcda53b63f88d2b9fa1d8 to your computer and use it in GitHub Desktop.
import { of } from 'rxjs';
import { switchMap, map, catchError } from 'rxjs/operators';
of(1, 2, 3, 4, 5).pipe(
switchMap(x => of(x)),
map(x => {
if (x != 3) {
return `x: ${x}`
}
throw 'x is 3';
}),
catchError(error => of(error)),
).subscribe(console.log);
console.log();
of(1, 2, 3, 4, 5).pipe(
switchMap(y => of(y).pipe(
map(y => {
if (y != 3) {
return `y: ${y}`
}
throw 'y is 3';
}),
catchError(error => of(error)),
)),
).subscribe(console.log);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment