Book description
Build optimized applications in Kotlin by learning how to smartly implement standard libraries.
Key Features
- Get the most out of the Kotlin library to develop high-quality portable applications
- Explore the powerful support for data processing and I/O operations
- Discover ways to enhance your Android application development
Book Description
Given the verbosity of Java, developers have turned to Kotlin for effective software development. The Kotlin standard library provides vital tools that make day-to-day Kotlin programming easier. This library features the core attributes of the language, such as algorithmic problems, design patterns, data processing, and working with files and data streams.
The recipes in this book offer coding solutions that can be readily executed. The book covers various topics related to data processing, I/O operations, and collections transformation. We'll walk through effective design patterns in Kotlin and you'll understand how coroutines add new features to JavaScript.
As you make your way through the chapters, you'll learn how to implement clean, reusable functions and scalable interfaces containing default implementations. In the concluding chapters, we'll provide recipes on functional programming concepts, such as lambdas, monads, functors, and Kotlin scoping functions.
By the end of the book, you'll be able to address a range of problems that Kotlin developers face by implementing easy-to-follow solutions.
What you will learn
- Work with ranges, progressions, and sequences in use cases
- Add new functionalities to current classes with Kotlin extensions
- Understand elements such as lambdas, closures, and monads
- Build a REST API consumer with Retrofit and a coroutine adapter
- Discover useful tips and solutions for making your Android projects
- Explore the benefits of standard library features
Who this book is for
This book is for software developers who are familiar with Kotlin's basics and want to discover more advanced features and concepts, especially those provided by the Kotlin standard library. It's also ideal for experienced software developers who are familiar with the functional programming paradigm and other programming languages who want to switch to Kotlin. It will also help Java developers switch to Kotlin and integrate it into existing Java Virtual Machine (JVM) projects.
Publisher resources
Table of contents
- Title Page
- Copyright and Credits
- Dedication
- Packt Upsell
- Contributors
- Preface
-
Ranges, Progressions, and Sequences
- Introduction
- Exploring the use of range expressions to iterate through alphabet characters
- Traversing through ranges using progression with a custom step value
- Building custom progressions to traverse dates
- Using range expressions with flow control statements
- Discovering the concept of sequences
- Applying sequences to solve algorithmic problems
-
Expressive Functions and Adjustable Interfaces
- Introduction
- Declaring adjustable functions with default parameters
- Declaring interfaces containing default implementations
- Extending functionalities of classes
- Destructuring types
- Returning multiple data
- Inlining parameters of closure type
- Infix notations for functions
- Smart types checking with generic reified parameters
- Overloading operators
-
Shaping Code with Kotlin Functional Programming Features
- Introduction
- Working effectively with lambda expressions
- Discovering basic scoping functions – let, also, apply
- Initializing objects the clean way using the run scoping function
- Working with higher-order functions
- Functions currying 
- Function composition
- Implementing the Either Monad design pattern
- Approach to automatic functions memoization 
- Powerful Data Processing
-
Tasteful Design Patterns Adopting Kotlin Concepts
- Introduction
- Implementing the Strategy pattern
- Exploring the power of the Delegation pattern
- Implementing delegated class properties
- Tracking state with the Observer pattern
- Restricting property updates with the Vetoable delegate
- Implementing the advanced Observer pattern by defining a custom property delegate
- Working with the Lazy delegate
- Implementing builders the smart way
- Friendly I/O Operations
-
Making Asynchronous Programming Great Again
- Introduction
- Executing tasks in the background using threads
- Background threads synchronization
- Using coroutines for asynchronous, concurrent execution of tasks
- Using coroutines for asynchronous, concurrent tasks execution with results handling
- Applying coroutines for asynchronous data processing
- Easy coroutine cancelation
- Building a REST API client with Retrofit and a coroutines adapter
- Wrapping third-party callback-style APIs with coroutines
-
Best Practices for the Android, JUnit, and JVM UI Frameworks
- Introduction
- Clean and safe view-binding with the Android Extensions plugin
- Applying coroutines for asynchronous UI programming on Android, JavaFX, and Swing
- Easy class serialization on Android using the @Parcelize annotation
- Implementing a custom property delegate that provides lifecycle-aware values
- Easy operations on SharedPreferences
- Less boilerplate Cursor data parsing
- Mocking dependencies with the Mockito Kotlin library
- Verifying function invocations
- Unit tests for Kotlin coroutines
-
Miscellaneous
- Introduction
- Kotlin and Java interoperability
- Kotlin and JavaScript interoperability
- Renaming generated functions
- Decompiling Kotlin code to Java and JVM bytecode
- Adding custom names for imports
- Wrapping complex type declarations with type aliases
- Expressive try…catch declarations
- Safe type-casting 
- Other Books You May Enjoy
Product information
- Title: Kotlin Standard Library Cookbook
- Author(s):
- Release date: July 2018
- Publisher(s): Packt Publishing
- ISBN: 9781788837668
You might also like
book
Android UI Development with Jetpack Compose
Get started with creating intuitive native user interfaces on Android platforms Key Features Understand the difference …
book
Learning Concurrency in Kotlin
Take advantage of Kotlin's concurrency primitives to write efficient multithreaded applications Key Features Learn Kotlin's unique …
book
The Complete Coding Interview Guide in Java
Explore a wide variety of popular interview questions and learn various techniques for breaking down tricky …
book
Java Coding Problems
Develop your coding skills by exploring Java concepts and techniques such as Strings, Objects and Types, …