Book Image

Kotlin Standard Library Cookbook

By : Samuel Urbanowicz
Book Image

Kotlin Standard Library Cookbook

By: Samuel Urbanowicz

Overview of this book

For developers who prefer a more simplistic approach to coding, Kotlin has emerged as a valuable solution for effective software development. The Kotlin standard library provides vital tools that make day-to-day Kotlin programming easier. This library features core attributes of the language, such as algorithmic problems, design patterns, data processing, and working with files and data streams. With a recipe-based approach, this book features coding solutions that you can readily execute. Through the book, you’ll encounter a variety of interesting topics related to data processing, I/O operations, and collections transformation. You’ll get started by exploring the most effective design patterns in Kotlin and understand how coroutines add new features to JavaScript. As you progress, you'll learn how to implement clean, reusable functions and scalable interfaces containing default implementations. Toward the concluding chapters, you’ll discover recipes on functional programming concepts, such as lambdas, monads, functors, and Kotlin scoping functions, which will help you tackle a range of real-life coding problems. By the end of this book, you'll be equipped with the expertise you need to address a range of challenges that Kotlin developers face by implementing easy-to-follow solutions.
Table of Contents (11 chapters)

Implementing delegated class properties

Class properties in Kotlin are more than just plain class fields. The key characteristic of Kotlin properties is the fact that their values are specified by accessor functions automatically. Each class property in Kotlin has a dedicated set of accessor functions available out of the box. By default, the Kotlin compiler generates a field storing the value of the property and its getters or setters as well. Each immutable val property has a corresponding get() function provided and the mutable one declared with var keyword has the set() function in addition to a get() as well. We are also able to override a default implementation of the accessor function, which makes a property highly customizable and powerful. For example, we can override the get() function of the property and provide a custom implementation for it, which can stop the compiler...