官术网_书友最值得收藏!

Functional reactive programming

The time has come to detail how to structure ReactiveX code in a functional way. It is tempting to name code designed this way functional reactive programming (FRP). Even though this name seems natural, it would be incorrectly named. FRP is something that was described by Conal Elliott in 1997 in a paper named Functional Reactive Animation. Functional reactive programming, as described by Conal Elliott, is composed of two types of values:

  • Events that correspond to real events, or generated ones
  • Behaviors that vary other continuous time

Events are the types of values that are implemented in ReactiveX observables. They can correspond to real events such as mouse location changes, some key presses on a keyboard, or a read operation that completes. Events are used to represent discrete values that change at specific times.

On the other hand, behaviors represent a value that is dependent on the time. So it is basically a formula, or a function, that is applied to the time. Behaviors always have a value, and they are used to represent continuous values depending on the current time. Behaviors are not available in ReactiveX. By the way, behaviors, as defined in the original paper, are available in no framework. This is due to the fact that the notion of a continuous value on a computer system does not exist. Some frameworks approximate behaviors by implementing them via sampling (that is, polling).

Since FRP is definitely not something that can be achieved with ReactiveX, writing functional code on top of a reactive framework should not be named FRP. However, with reactive programming and functional programming being more and more popular, and as they are more and more combined, this is often a source of confusion. The number of questions related to this on development discussion channels confirms this. Another similar name is used by several libraries: functional and reactive programming (FARP). The difference is both subtle and very clear: FARP is not FRP, but reactive code written in a functional way. This is the terminology that will be used in this book.

主站蜘蛛池模板: 太谷县| 和硕县| 英吉沙县| 文成县| 南木林县| 布尔津县| 呼伦贝尔市| 瑞金市| 乡宁县| 天水市| 浪卡子县| 上饶县| 巴楚县| 特克斯县| 开阳县| 方城县| 津市市| 黔西| 岑巩县| 泰宁县| 隆子县| 新密市| 乐山市| 江达县| 白山市| 天津市| 石台县| 甘南县| 云龙县| 澄迈县| 南康市| 梅河口市| 海阳市| 微山县| 浠水县| 苍山县| 龙江县| 昭觉县| 鲁甸县| 临朐县| 彭阳县|