What is Reactive Programming?
The difference between a "Reactive" and "Interactive" program is that, a Reactive program only executes in response to an input. Consider a very prototypical "Interactive" program, a Compiler. It takes a list of files, transforms data, spits out an output, then it's done. Fin.
Reactive programs don't really have a done - consider an Operating System. When is it "done"? It keeps running forever, responding to inputs from the outside world (network, input devices, etc). Or consider "Notepad.exe". It always has more work to do, until the user selects the "Exit" menu item. So, every GUI app you've ever written is a Reactive program - it is based on events that generally have no discrete termination.
Cool. Where does "Functional" come in?
One of the most important aspects of Functional Reactive programming, is that events are first-class. This means, that you can create an Event and just assign it to a variable. In Rx, the Type of this variable is IObservable<T>
. Because events are Just Variables, we can combine them together to build more interesting events.
We can take those events and combine them even further too, and use them to build even more interesting events, or we can build operators that encapsulate behaviors like "Timeout" or "Retry", without tying ourselves to what kind of event the source is.