Transformation Operators
Use map, switchMap, mergeMap, and concatMap.
Transformation Operators is a free Angular Academy lesson on CoddyKit. This is lesson 1 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Angular Academy learning path, and your progress syncs across the web and the CoddyKit app. The Angular Academy course includes 4 lessons in total.
What are operators
Operators are functions you compose inside .pipe() to transform a stream. Transformation operators change each emitted value or flatten inner observables into the output.
map
map transforms each emitted value, like Array.map but over time.
import { of, map } from 'rxjs';
of(1, 2, 3).pipe(
map(n => n * 10)
).subscribe(v => console.log(v)); // 10, 20, 30Why higher-order mapping
When each value triggers another observable (e.g. an HTTP call), you get an observable-of-observables. Flattening operators (switchMap, mergeMap, concatMap) subscribe to the inner one and emit its values.
switchMap
switchMap cancels the previous inner observable when a new value arrives. Perfect for type-ahead search — old requests are discarded.
import { switchMap } from 'rxjs';
searchTerm$.pipe(
switchMap(term => this.http.get('/api/search?q=' + term))
).subscribe(results => console.log(results));mergeMap
mergeMap (alias flatMap) runs inner observables concurrently and merges all their emissions. Nothing is cancelled.
import { mergeMap } from 'rxjs';
ids$.pipe(
mergeMap(id => this.http.get('/api/item/' + id))
).subscribe(item => console.log(item));
// all requests run in parallelconcatMap
concatMap queues inner observables and runs them one at a time in order, waiting for each to complete. Use it when order matters.
import { concatMap } from 'rxjs';
saveQueue$.pipe(
concatMap(payload => this.http.post('/api/save', payload))
).subscribe();
// requests run sequentially, in orderexhaustMap
exhaustMap ignores new values while an inner observable is still running. Great for preventing double-submits on a button click.
import { exhaustMap } from 'rxjs';
submitClicks$.pipe(
exhaustMap(() => this.http.post('/api/login', creds))
).subscribe();
// extra clicks ignored until request finishesChoosing the right flattener
switchMap: cancel previous (search).
mergeMap: all in parallel (independent writes).
concatMap: ordered, one by one (sequential saves).
exhaustMap: ignore while busy (login button).
switchMap and cancellation
Because switchMap cancels in-flight inner observables, it also unsubscribes the underlying HTTP request, which Angular translates into an aborted request — saving bandwidth.
Combining map with a flattener
You often map to extract data after flattening.
searchTerm$.pipe(
switchMap(term => this.http.get('/api/search?q=' + term)),
map(res => res.items)
).subscribe(items => console.log(items));Avoid nested subscribes
Never subscribe inside a subscribe. Use a flattening operator instead — it keeps the pipeline declarative and handles cleanup correctly.
// BAD:
// outer$.subscribe(v => inner$(v).subscribe(...));
// GOOD:
// outer$.pipe(switchMap(v => inner$(v))).subscribe(...);Quick Check
Test your understanding of transformation operators.
Recap: Transformation Operators
map transforms values; flattening operators handle inner observables.
switchMap: cancel previous.mergeMap: parallel.concatMap: sequential, ordered.exhaustMap: ignore while busy.
Next: filtering operators.
Learn HTML with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 38
- Lessons
- 144
Frequently Asked Questions
Is the “Transformation Operators” lesson free?
Yes — any 3 lessons of the Angular Academy learning path, including “Transformation Operators”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Angular Academy course includes 4 lessons in total.
What will I learn in “Transformation Operators”?
Use map, switchMap, mergeMap, and concatMap. You practise Angular Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Angular Academy?
No prior experience is required. Angular Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 4.
How long does the “Transformation Operators” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Angular Academy lesson?
Yes. Every Angular Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Transformation Operators
- Filtering Operators
- Combination Operators
- Error Handling Operators