惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
WordPress大学
WordPress大学
阮一峰的网络日志
阮一峰的网络日志
博客园 - 司徒正美
月光博客
月光博客
宝玉的分享
宝玉的分享
Recent Announcements
Recent Announcements
小众软件
小众软件
H
Hackread – Cybersecurity News, Data Breaches, AI and More
美团技术团队
博客园 - 三生石上(FineUI控件)
A
About on SuperTechFans
J
Java Code Geeks
云风的 BLOG
云风的 BLOG
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家
Vercel News
Vercel News
量子位
Martin Fowler
Martin Fowler
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
腾讯CDC
有赞技术团队
有赞技术团队

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
RxJS Is Just Arrays Over Time
Amrishkhan Sheik Abdullah · 2026-06-05 · via DEV Community

RxJS has a reputation problem.

Mention RxJS in a JavaScript discussion and you'll usually get one of two reactions.

The first:

I love RxJS.

Enter fullscreen mode Exit fullscreen mode

The second:

I have no idea what's going on.

Enter fullscreen mode Exit fullscreen mode

There is rarely an in-between.

And honestly, I understand why.

Most RxJS tutorials immediately throw developers into a sea of operators:

map
filter
switchMap
mergeMap
concatMap
combineLatest
forkJoin
zip
scan

Enter fullscreen mode Exit fullscreen mode

It feels like learning an entirely new programming language.

But what if I told you that most RxJS operators are concepts you already know?

What if the problem isn't RxJS?

What if the problem is how RxJS is taught?

Because once I understood one simple idea, RxJS suddenly became much easier:

RxJS is just Arrays over Time.

Not exactly.

But close enough that it dramatically simplifies how you think about Observables.


Start With Something Familiar

Consider an Array.

const numbers = [1, 2, 3, 4]

Enter fullscreen mode Exit fullscreen mode

We can transform it.

const doubled = numbers.map(
  x => x * 2
)

console.log(doubled)

Enter fullscreen mode Exit fullscreen mode

Output:

[2, 4, 6, 8]

Enter fullscreen mode Exit fullscreen mode

We can filter it.

const even = numbers.filter(
  x => x % 2 === 0
)

Enter fullscreen mode Exit fullscreen mode

Output:

[2, 4]

Enter fullscreen mode Exit fullscreen mode

We can reduce it.

const total = numbers.reduce(
  (sum, x) => sum + x,
  0
)

Enter fullscreen mode Exit fullscreen mode

Output:

10

Enter fullscreen mode Exit fullscreen mode

Nothing surprising.

Every JavaScript developer understands this.


Now Imagine The Values Arrive Over Time

Instead of:

[1,2,3,4]

Enter fullscreen mode Exit fullscreen mode

imagine:

1
(wait)
2
(wait)
3
(wait)
4

Enter fullscreen mode Exit fullscreen mode

The values are the same.

The only difference is:

Space
↓

Time

Enter fullscreen mode Exit fullscreen mode

That is the key insight.


Enter Observables

An Observable might emit:

1
2
3
4

Enter fullscreen mode Exit fullscreen mode

over time.

Example:

import {
  interval
} from "rxjs"

interval(1000)

Enter fullscreen mode Exit fullscreen mode

Output:

0
1
2
3
4
...

Enter fullscreen mode Exit fullscreen mode

One value every second.

Instead of holding values simultaneously like an Array, an Observable delivers values gradually.


map() Works Exactly The Same

Array:

[1, 2, 3]
  .map(x => x * 2)

Enter fullscreen mode Exit fullscreen mode

Observable:

interval(1000)
  .pipe(
    map(x => x * 2)
  )

Enter fullscreen mode Exit fullscreen mode

Output:

0
2
4
6
8
...

Enter fullscreen mode Exit fullscreen mode

The transformation is identical.

Only the timing differs.


filter() Works Exactly The Same

Array:

numbers.filter(
  x => x % 2 === 0
)

Enter fullscreen mode Exit fullscreen mode

Observable:

interval(1000)
  .pipe(
    filter(
      x => x % 2 === 0
    )
  )

Enter fullscreen mode Exit fullscreen mode

Output:

0
2
4
6
8
...

Enter fullscreen mode Exit fullscreen mode

Again:

Same operation.

Different delivery mechanism.


scan() Is Reduce For Infinite Data

This is where many RxJS developers finally have their "aha" moment.

Arrays use:

reduce()

Enter fullscreen mode Exit fullscreen mode

Example:

[1, 2, 3, 4]
  .reduce(
    (sum, x) => sum + x,
    0
  )

Enter fullscreen mode Exit fullscreen mode

Output:

10

Enter fullscreen mode Exit fullscreen mode

But Observables can be infinite.

They never finish.

So:

reduce()

Enter fullscreen mode Exit fullscreen mode

often doesn't make sense.

Instead RxJS gives us:

scan()

Enter fullscreen mode Exit fullscreen mode

Example:

interval(1000)
  .pipe(
    scan(
      (sum, x) => sum + x,
      0
    )
  )

Enter fullscreen mode Exit fullscreen mode

Output:

0
1
3
6
10
15
21
...

Enter fullscreen mode Exit fullscreen mode

This is:

Reduce
Over Time

Enter fullscreen mode Exit fullscreen mode

And once you see that, scan becomes incredibly intuitive.


flatMap Exists Here Too

In the previous article we discussed:

flatMap()

Enter fullscreen mode Exit fullscreen mode

Arrays:

users.flatMap(
  user => user.permissions
)

Enter fullscreen mode Exit fullscreen mode

RxJS:

searchText$
  .pipe(
    mergeMap(
      text =>
        api.search(text)
    )
  )

Enter fullscreen mode Exit fullscreen mode

Same problem.

Same solution.

The difference is:

Arrays
↓

Nested Collections

Enter fullscreen mode Exit fullscreen mode

versus

Observables
↓

Nested Streams

Enter fullscreen mode Exit fullscreen mode


switchMap, mergeMap and concatMap

These operators confuse almost everyone initially.

The reason is simple.

Arrays don't have time.

Observables do.

Suppose:

Search A
Search B
Search C

Enter fullscreen mode Exit fullscreen mode

happen rapidly.

Now:

Which API calls should survive?

Enter fullscreen mode Exit fullscreen mode

That is what these operators answer.


mergeMap

Run everything.

A
B
C

All continue.

Enter fullscreen mode Exit fullscreen mode


concatMap

Queue everything.

A
↓

B
↓

C

Enter fullscreen mode Exit fullscreen mode


switchMap

Cancel old work.

A ❌

B ❌

C ✅

Enter fullscreen mode Exit fullscreen mode

Perfect for search boxes.


Why RxJS Feels Hard

Because developers often memorize operators.

Instead of understanding patterns.

If you think:

map
filter
scan
flatMap

Enter fullscreen mode Exit fullscreen mode

then RxJS becomes much simpler.

Because you've already seen these concepts before.

In Arrays.


Real World Example: Search Autocomplete

User types:

a
ap
app
appl
apple

Enter fullscreen mode Exit fullscreen mode

Without RxJS:

You manually manage:

  • timers
  • cancellation
  • race conditions

With RxJS:

search$
  .pipe(
    debounceTime(300),
    distinctUntilChanged(),
    switchMap(
      query =>
        api.search(query)
    )
  )

Enter fullscreen mode Exit fullscreen mode

This is why RxJS exists.

It turns asynchronous complexity into composable transformations.


Real World Example: WebSocket Streams

Messages arrive continuously.

Message 1
Message 2
Message 3

Enter fullscreen mode Exit fullscreen mode

Treating them as a stream allows:

messages$
  .pipe(
    filter(
      msg => msg.priority
    ),
    map(
      msg => msg.payload
    )
  )

Enter fullscreen mode Exit fullscreen mode

Exactly like Arrays.

Except the values arrive over time.


Performance Considerations

Arrays:

array
  .map(...)
  .filter(...)

Enter fullscreen mode Exit fullscreen mode

may create intermediate arrays.

RxJS:

stream
  .pipe(
    map(...),
    filter(...)
  )

Enter fullscreen mode Exit fullscreen mode

usually processes values incrementally.

One item at a time.

This can significantly reduce memory pressure for large streams.


Pros Of Thinking This Way

1. RxJS Becomes Easier

Most operators stop feeling magical.


2. Reuse Existing Knowledge

Array knowledge transfers directly.


3. Better Mental Models

Patterns become obvious.


4. Easier Debugging

You stop treating operators as black boxes.


5. Strong Foundation For Reactive Programming

Everything else builds on these concepts.


Cons Of The Analogy

1. Arrays Are Finite

Observables may be infinite.


2. Time Changes Everything

Cancellation becomes important.


3. Concurrency Doesn't Exist In Arrays

RxJS operators must handle it.


4. Error Handling Differs

Streams behave differently from collections.


5. The Analogy Eventually Breaks

At advanced levels.

But it remains extremely useful.


The Real Lesson

The biggest mistake people make with RxJS is treating it as something completely new.

It isn't.

Most of its core ideas already exist in JavaScript.

You've seen:

map()
filter()
reduce()
flatMap()

Enter fullscreen mode Exit fullscreen mode

before.

RxJS simply applies those ideas to values that arrive over time.

And once you realize that:

Observable

≈

Array Over Time

Enter fullscreen mode Exit fullscreen mode

the entire library becomes much less intimidating.

Not because the complexity disappeared.

But because you finally have a mental model that makes sense.


What's Next?

In the next article we'll revisit one of the most misunderstood operators in RxJS:

scan() Is Reduce For Infinite Data

Because understanding scan() unlocks:

  • RxJS state management
  • Redux-like patterns
  • Event sourcing
  • Reactive architectures

and ultimately connects everything back to the humble reduce() function where this series began.


About The Author

Hi, I'm Amrish Khan.

I enjoy building developer tools, exploring software architecture, and writing about the deeper ideas behind everyday programming concepts.

I'm also building Aruvix — a growing ecosystem of local-first developer tools designed to process data directly in the browser without unnecessary uploads.

Here's a detailed blog on Aruvix:

https://dev.to/amrishkhan05/aruvix-the-ultimate-offline-first-developer-toolkit-e0i

You can follow my work and thoughts here:

Portfolio:
https://www.amrishkhan.dev

LinkedIn:
https://www.linkedin.com/in/amrishkhan

GitHub:
https://www.github.com/amrishkhan05

If you enjoyed this article, consider following for more deep dives into JavaScript, architecture, local-first software, and performance engineering.