DEV Community

Cover image for Reactive programming in Android
Evans Mutwiri
Evans Mutwiri

Posted on

Reactive programming in Android

I am learning a rather huge code base and.... well.

Reactive programming is a design paradigm that handles real-time updates to otherwise static content using asynchronous programming logic. It provides an efficient method for handling data updates to content whenever a user makes an inquiry (via automated data streams).

Imperative vs Reactive

Reactive programming is declarative as opposed to imperative.
Imperative programming is programming "how to do something"

Imperative example

val result = mutableListOf<Int>()

    for (i in 1..5) {
        result.add(i)
    }

    println("result is $result")
Enter fullscreen mode Exit fullscreen mode

Reactive example

    val result = (1..5).map { it }

    println("Declaritive result $result")
Enter fullscreen mode Exit fullscreen mode

From the examples, if imperative programming is food recipe, then reactive programming is ordering food!

Kotlin collections api

Kotlin collections api makes reactive programming easy as knowledge of the existence. There are about 200 of them.

Cheatsheet

Top comments (0)