0Pricing
Angular Academy · Lesson

Transformation Operators

Use map, switchMap, mergeMap, and concatMap.

Transformation Operators is a free Angular Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Angular Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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, 30

Why 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 parallel

concatMap

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 order

exhaustMap

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 finishes

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

Frequently asked questions

Is the “Transformation Operators” lesson free?

Yes — the full text of “Transformation Operators” is free to read here on the web, and the Angular Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Angular Academy course, upgrade to CoddyKit PRO.

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; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

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

  1. Transformation Operators
  2. Filtering Operators
  3. Combination Operators
  4. Error Handling Operators
← Back to Angular Academy