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

What is reactive programming?

Reactive programming is an asynchronous programming paradigm that revolves around data streams and the propagation of change. In simpler words, those programs which propagate all the changes that affected its data/data streams to all the interested parties (such as end users, components and sub-parts, and other programs that are somehow related) are called reactive programs.

For example, take any spreadsheet (say the Google Sheet), put any number in the A1 cell, and in the B1 cell, write the =ISEVEN(A1) function; it'll show TRUE or  FALSE, depending on whether you've entered an even or odd number. Now, if you modify the number in A1, the value of B1 will also get changed automatically; such behavior is called reactive.

Not clear enough? Let's look at a coding example and then try to understand it again. The following is a normal Kotlin code block to determine if a number is even or odd:

    fun main(args: Array<String>) { 
      var number = 4 
      var isEven = isEven(number) 
      println("The number is " + (if (isEven) "Even" else "Odd")) 
      number = 9 
      println("The number is " + (if (isEven) "Even" else "Odd")) 
    } 
 
    fun isEven(n:Int):Boolean = ((n % 2) == 0) 

If you check the output of the program, then you'll see that, although the number is assigned a new value, isEven is still true; however, if isEven was made to track changes of the number, then it would automatically become false. A reactive program would just do the same.

主站蜘蛛池模板: 洪湖市| 浮梁县| 察雅县| 报价| 太仆寺旗| 闽侯县| 敦煌市| 定襄县| 衢州市| 华容县| 威信县| 托克逊县| 肥东县| 胶州市| 武夷山市| 文成县| 连云港市| 金溪县| 葫芦岛市| 桐乡市| 沁源县| 乌拉特后旗| 巴南区| 纳雍县| 应城市| 兴宁市| 茌平县| 顺义区| 南木林县| 会泽县| 衡山县| 清水河县| 合阳县| 枣阳市| 卓资县| 东平县| 阿荣旗| 安阳市| 崇义县| 吉木萨尔县| 裕民县|