Efficiency Through Pipelines
Learn how chaining in the pipeline works in increasing the efficiency.
We'll cover the following
The first time I chained a bunch of operators into a pipeline to transform a sequence, my gut feeling was that it couldn’t possibly be efficient. I knew transforming arrays in JavaScript by chaining operators is expensive. Yet in this course, we’ll design our program by transforming sequences into new ones. Isn’t that terribly inefficient?
Chaining in the pipeline
Chaining looks similar in Observables and in arrays; there are even methods like filter
and map
that are present in both types. But there’s a crucial difference:
Array methods create a new array as a result of each operation, which is traversed entirely by the next operation.
Observable pipelines, on the other hand, don’t create intermediate Observables and apply all operations to each element in one go. The Observable is thus traversed only once, which makes chaining Observables efficient.
Check out the following example:
Get hands-on with 1200+ tech skills courses.