Chapter 1. Stop listening!


This chapter covers

  • What FRP is
  • What events are, and how they cause trouble
  • What FRP is for: the problem we’re trying to solve
  • The benefits of FRP
  • How an FRP system works
  • A different way of thinking that underlies FRP

Welcome to our book! We love functional reactive programming (FRP). Many people like the idea too, yet they aren’t entirely clear what FRP is and what it will do for them. The short answer: it comes in the form of a simple library in a standard programming language, and it replaces listeners (also known as callbacks) in the widely used observer pattern, making your code cleaner, clearer, more robust, and more maintainable—in a word, simpler.

It’s more than this: FRP is a very different way of doing things. It will improve your code and transform your thinking for the better. Yet it’s surprisingly compatible with the usual ways of writing code, so it’s easy to factor into existing projects in stages. This book is about the concepts of FRP as they apply to a range of FRP systems and programming languages.

FRP is based on ideas from functional programming, but this book doesn’t assume any prior knowledge of functional programming. Chapter 1 will lay down some underlying concepts, and in chapter 2 we’ll get into the coding. So stop listening, and start reacting!

1.1. Project, meet complexity wall

1.2. What is functional reactive programming?

1.3. Where does FRP fit in? The lay of the land

1.4. Interactive applications: what are events?

1.5. State machines are hard to reason about

1.6. Interactive applications without the bugs

1.7. Listeners are a mainstay of event handling, but ...

1.8. Banishing the six plagues of listeners

1.9. Why not just fix listeners?

1.10. “Have you tried restarting it?” or why state is problematic

1.11. The benefit of FRP: dealing with complexity

1.12. How does FRP work?

1.13. Paradigm shift

1.14. Thinking in terms of dependency

1.15. Thinking declaratively: what the program is, not what it does

1.16. Conceptual vs. operational understanding of FRP

1.17. Applying functional programming to event-based code

1.18. Summary