Reactive programming treats changing or asynchronous data as streams of ordered events over time. Instead of giving files, web requests, database queries, notifications, user input, collections, and strings separate control flows, it lets code observe them through one model: subscribe to a stream, transform its values, and react to results. section 8.4
This style is useful when event-handling code would otherwise mix input reading, cleanup, validation, state changes, and output in one callback. A reactive pipeline separates those jobs into small operations, so each incoming value flows through the same sequence of transformations. Functional reactive programming raises the abstraction level by treating events as logically independent units rather than exposing temporal implementation details. section 1.3 section 8.5
Validate input as an event stream
An imperative SSN handler reads the field on every key press, removes spaces and dashes, checks its length, and changes a valid flag. With Rx.Observable.fromEvent, the input becomes a stream: pluck its value, map a cleanup function, filter values whose length is nine, then subscribe to valid SSNs. Each step has one purpose, and invalid values never reach the final subscriber. section 1.3 section 8.4
RxJS pipelines commonly use these parts:
- Create or lift a source into an observable, such as a number range, a promise, an event, or a collection. section 8.4
- Transform or select emitted values with operations such as map and filter. section 8.4
- Subscribe to receive next values, errors, and completion notifications. section 8.4
- Flatten a stream when an asynchronous source produces further observable values, as with a JSON request followed by individual students. section 8.4
Figure 8.12. The process of applying functions filter and map from an observable sequence of numbers
This diagram makes the pipeline visible: values enter an observable sequence, filter removes unwanted values, and map transforms those that remain. section 8.4
Reactive programming builds on functional composition. Lazy generators similarly model data as values produced on demand and passed through pure higher-order functions, but observables add subscription and support asynchronous event sources. In JavaScript, chained calls make the flow readable while deferring the details of when values arrive. section 8.3 section 8.4





