Book Image

Functional Kotlin

Book Image

Functional Kotlin

Overview of this book

Functional programming makes your application faster, improves performance, and increases your productivity. Kotlin supports many of the popular and advanced functional features of functional languages. This book will cover the A-Z of functional programming in Kotlin. This book bridges the language gap for Kotlin developers by showing you how to create and consume functional constructs in Kotlin. We also bridge the domain gap by showing how functional constructs can be applied in business scenarios. We’ll take you through lambdas, pattern matching, immutability, and help you develop a deep understanding of the concepts and practices of functional programming. If you want learn to address problems using Recursion, Koltin has support for it as well. You’ll also learn how to use the funKtionale library to perform currying and lazy programming and more. Finally, you’ll learn functional design patterns and techniques that will make you a better programmer.By the end of the book, you will be more confident in your functional programming skills and will be able to apply them while programming in Kotlin.
Table of Contents (22 chapters)
Title Page
Copyright and Credits
Dedication
Packt Upsell
Contributors
Preface
Index

Subscriber – the Observer interface


In RxKotlin 1.x, the Subscriber operator essentially became an Observer type in RxKotlin 2.x. There is an Observer type in RxKotlin 1.x, but the Subscriber value is what you pass to the subscribe() method, and it implements Observer. In RxJava 2.x, a Subscriber operator only exists when talking about Flowables

As you can see in the previous examples in this chapter, an Observer type is an interface with four methods in it, namely onNext(item:T), onError(error:Throwable), onComplete(), and onSubscribe(d:Disposable). As stated earlier, when we connect Observable to Observer, it looks for these four methods in the Observer type and calls them. Here is a short description of the following four methods:

  • onNext: The Observable calls this method of Observer to pass each of the items one by one
  • onComplete: When the Observable wants to denote that it's done with passing items to the onNext method, it calls the onComplete method of Observer
  • onError: When Observable...