Building sequences

As I mentioned earlier, Kotlin coroutines are something more than threads in Java and async/await in C#. Here is a feature that, after learning, you will be pissed that it was not there while you were learning to code. To add icing on the cake, this feature is application level, it is even shipped with kotlin-stdlib, so you can use it right there without doing anything or even using coroutines explicitly.

Before learning what I am talking about, let's do some old school code, say the fibonacci series? Consider the following piece of code as an example:

    fun main(args: Array<String>) { 
      var a = 0 
      var b = 1 
      print("$a, ") 
      print("$b, ") 
 
      for(i in 2..9) { 
        val c = a+b 
        print("$c, ") 
        a=b 
        b=c 
      } 
    } 

So, this is the old-school fibonacci ...

Get Reactive Programming in Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.