I have a basic question regarding the distinction between synchronous and asynchronous operators and sequences.
In programming, everything can be represented as a sequence. For example:
- An array of numbers can be considered a sequence that is traditionally processed synchronously using functions like
reduce
to calculate a sum or average where all elements need to be known in advance. - An array of click events are examples of an asynchronous sequence which may come in the future with unknown arrival times and quantities.
The Observable
datatype allows for various operations on elements in a sequence such as merge
, zip
, and more.
RxJS treats sequences asynchronously. So my question is - what's the purpose of operators like average, count, max, min, reduce, etc., that require the sequence to be completed? If we cannot asynchronously add elements to a sequence for recalculations, why choose RxJS over Array.prototype.reduce?
In essence, I initially thought that sequences should be operable (regardless of the operation) even when they are incomplete.