Functional Kotlin:

Who is this book for
This book is perfect for developers who know the basics of Kotlin and want to learn more advanced features. Math knowledge is NOT required to understand and benefit from this book. It is a natural continuation of Kotlin Essentials.
What you will learn
This book focuses on Kotlin’s functional features, including: - Generic variance modifiers - Covariant Nothing Object pattern - Generic variance modifier limitations - Interface delegation - Implementing custom property delegate - Property delegates from Kotlin stdlib - Kotlin Contracts - Kotlin and Java type mapping - Annotations for Kotlin and Java interoperability - Multiplatform development structure, concepts and possibilities - Implementing multiplatform library - Implementing Android and iOS applications with shared module - Essentials of Kotlin/JS - Reflecting Kotlin elements - Reflecting Kotlin types - Implementing custom Annotation Processor - Implementing custom Kotlin Symbol Processor - KSP incremental compilation and multiple round processing - Defining Compiler Plugin - Core Static Analysis concepts - Overview of Kotlin static analyzers - Defining custom Detekt rule This book is full of example projects, including: - Type-safe task update class using Covariant Nothing Object pattern (Generic variance modifiers chapter) - Logging property delegate (Property delegation chapter) - Object serializer (Reflection chapter) - Random value generator for generic types (Reflection chapter) - Annotation Processor generating interface for a class (Annotation Processing chapter). - Kolin Symbol Processor generating interface for a class (Kotlin Symbol Processing chapter). - Detekt rule finding <code>System.out.println</code> usage.
Chapter by Chapter
Clear path to progress
- Who is this book for?
- What will be covered?
- The Kotlin for Developers series
- Conventions
- Code conventions
- Exercises and solutions
- Acknowledgments
- Why do we need to use functions as objects?
- Defining function types
- Using function types
- Named parameters
- Type aliases
- A function type is an interface
- Tricky braces
- Parameters
- Trailing lambdas
- Result values
- Lambda expression examples
- An implicit name for a single parameter
- Closures
- Lambda expressions vs anonymous functions
- Exercise: Function types and literals
- Exercise: Observable value
- Top-level functions references
- Method references
- Extension function references
- Method references and generic types
- Bounded function references
- Constructor references
- Bounded object declaration references
- Function overloading and references
- Property references
- Exercise: Inferred function types
- Exercise: Function references
- Support for Java SAM interfaces in Kotlin
- Functional interfaces
- Inline functions
- Inline functions with functional parameters
- Non-local return
- Crossinline and noinline
- Reified type parameters
- Inline properties
- Costs of the inline modifier
- Using inline functions
- Exercise: Inline functions
- forEach and onEach
- filter
- map
- mapNotNull
- flatMap
- Exercise: Implement map
- Exercise: Optimize collection processing
- fold
- reduce
- sum
- withIndex and indexed variants
- take, takeLast, drop, dropLast and subList
- Exercise: Adding element at position
- Getting elements at certain positions
- Finding an element
- Counting elements
- any, all and none
- Exercise: Implement shop functions
- partition
- groupBy
- Associating to a map
- distinct and distinctBy
- Exercise: Prime access list
- Sorting: sorted, sortedBy and sortedWith
- Sorting mutable collections
- Maximum and minimum
- shuffled and random
- Exercise: Top articles
- Exercise: Refactor collection processing
- zip and zipWithNext
- Windowing
- joinToString
- Map, Set and String processing
- Exercise: Passing students list
- Exercise: Best students list
- Exercise: Functional Quick Sort
- Exercise: Powerset
- Exercise: All possible partitions of a set
- What is a sequence?
- Order is important
- Sequences do the minimum number of operations
- Sequences can be infinite
- Sequences do not create collections at every processing step
- When aren’t sequences faster?
- What about Java streams?
- Kotlin Sequence debugging
- Summary
- Exercise: Understanding sequences
- A function type with a receiver
- Simple DSL builders
- Using apply
- Simple DSL-like builders
- Multi-level DSLs
- DslMarker
- A more complex example
- When should we use DSLs?
- Summary
- Exercise: HTML table DSL
- Exercise: Creating user table row
- let
- also
- takeIf and takeUnless
- apply
- The dangers of careless receiver overloading
- with
- run
- Using scope functions
- Exercise: Using scope functions
- Exercise: orThrow
- Extension function problems
- Introducing context parameters
- Use cases
- Concerns
- Named context parameters
- Summary
- Exercise: Logger
- Functions and Arrow Core
- Testing higher-order functions
- Error Handling
- Data Immutability with Arrow Optics
- Final Project: UserService