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

Property delegation (standard delegates)


In the previous section, where we discussed delegation, we learned that delegation is a technique of method passing/forwarding.

For property delegates, it almost does the same. A property can pass its getter and setter calls to the delegate and the delegate can handle those calls on behalf of the property itself.

You're probably thinking, what is the benefit of passing getter and setter calls to the delegate? Only the delegate you're using can answer this question. Kotlin has multiple predefined standard delegations for most common use cases. Let's have a look at the following list, containing available standard delegates:

  • The Delegates.notNull function and lateinit
  • The lazy function
  • The Delegates.Observable function
  • The Delegates.vetoble function

The Delegates.notNull function and lateinit

Think of a situation where you need to declare a property at the class level, but you don't have the initial value for the variable there. You'll get the value at some...