This document discusses functional reactive programming (FRP). It begins by defining FRP as combining functional programming with reactive programming, where signals emit values over time in a declarative rather than imperative style. It provides examples of how FRP can be used to search APIs reactively based on user input and start/stop timers based on user gestures. The document notes advantages of FRP like conciseness, readability, ease of asynchronous programming, and maintainability. It outlines some FRP concepts like observables, transformations, composition, and filtering. It acknowledges criticisms of FRP's complexity but argues that FRP is actually simple and that simplicity should be the goal. It predicts FRP will become increasingly important.
20. Example 2
When the user starts simultaneously panning and
rotating an object, start a countdown from 3.
Stop the timer either when the countdown ends
or when the user stops the gestures.
23. Imperative
- When the user touches the screen
- Check if a user is panning an object, store that information
- Check if both gestures are running simultaneously
- start a timer, from 3, counting down.
- Check if the user is rotating an object, store that information
- Check if both gestures are running simultaneously
- start a timer, from 3, counting down.
- Check if the user stopped panning
- Stop the timer if needed
- Check if the user stopped rotating
- Stop the timer if needed
- When the timer ticks, decrease the number of seconds left
- If the number of seconds left is zero, stop the timer*
32. Declarative
Define condition “simultaneously `panning` and `rotating`”
Define condition “start a countdown from `3`”
Define condition “when the user stops the gestures”
Define what a timer is
When the user starts simultaneously `panning` and `rotating` an object, start a countdown from `3`.
Stop the timer either when the countdown ends or when the user stops the gestures.”
33. Advantages
• Code more concise & clear, easy to
understand without context
• Readability, highly express
• Make Asynchronous easier
• UI Binding
• Maintainability, Extensibility
...