Chapter 11. Programming in the real world
This chapter covers
- Dealing with I/O
- Working with promises and futures
- Distributed processing
- Unit testing
Functional programming in general gives you an idealized programming model, allowing you to focus on the problem itself, and FRP does this too. In chapter 9, you bounced a ball in an ideal world of continuous time, as if in some Zen squash court from the movie The Matrix. Earlier, chapter 8 covered some of the uncharted, more operational areas of the FRP design space. But sooner or later, you’ll have to deal with something even more terrifying: the real world.
I/O is notorious for presenting intractable difficulties and complexities. I/O and logic tend to mutually complicate each other, so the approach used in FRP—and in functional programming in general—is to keep them separate. FRP deals well with the complexities of logic, and I/O is simpler with the logic removed.
When the input stream fires, the I/O is initiated, and when the result of the I/O is ready, it appears on the output stream. The operation is asynchronous, so the output is in a different transactional context from the I/O initiation event.
The needs of Sodium in Java require you to write that type concretely as shown here, but of course, each language has its own way of representing function types: