What is a Stream?
In a functional reactive world, streams are lists of events over time. But in Apex, with code running in its own execution context, we can hardly build an asynchronous stream. So in Stream.apex, we have only synchronous streams, which are just lists.
R.apex has already tons of functions to operate on lists, and then what is the point to build a stream?
Well, streams are actully event-driven lists. In R.apex, we do a map
on the list, and get a new list. Then we operate on the new list, and continue. In Stream.apex, event-driven lists are different. Streams do not need to create any intermediate lists because they just work in place. When an element in a list is processed, it is treated as an event, and passed through all the operations in the stream chains. This goes on until this single element is fully processed, before the next element gets fired. In this way, streams are modelled like event-driven lists, and each stream receives events and notifies events.