Functional Programming in Kotlin
Functional Programming in Kotlin
Summary:
Introduction
The book «Functional Programming in Kotlin» (authors: Marco Vermeulen, Rúnar Bjarnason, Paul Chiusano, 2021, 360 pages) is an adaptation of the famous bestseller «Functional Programming in Scala» for the Kotlin language. It offers a deep dive into the functional programming (FP) paradigm using modern Kotlin features. Despite the site being dedicated to Python, this book will be useful for anyone who wants to master FP on a strictly typed JVM language and transfer the acquired knowledge to other languages, including Python.
What the book is about
The book starts with the basics: pure functions, immutability, referential transparency. It then sequentially introduces key FP concepts: higher-order functions, currying, composition. The main part is dedicated to working with data types: Option, Either, List, Stream and building functional libraries based on them. The authors thoroughly examine monads, functors, applicative functors, and monad transformers. Special attention is given to testing, parallelism, and working with state in a pure functional style.
Who this book is for
- Kotlin developers wanting to learn functional programming from scratch.
- Programmers in Java or other JVM languages transitioning to Kotlin and interested in FP.
- Specialists familiar with FP in Scala or Haskell but wanting to see an implementation in Kotlin.
- Anyone who wants to write more reliable, testable, and predictable code.
What the reader will learn
- FP basics: pure functions, immutability, absence of side effects.
- Working with higher-order functions and lambdas in Kotlin.
- Creating and using functional data structures (List, Tree, Stream).
- Understanding and implementing functors, applicative functors, and monads.
- Error handling without exceptions (Option, Either).
- Functional parallelism and working with state.
- Testing functional code using property-based testing.
- Building your own libraries for FP.
Strengths
The main advantage of the book is its practical focus. Each concept is not just explained but also implemented from scratch. The reader writes their own functional libraries, which provides deep understanding. The Kotlin code is modern and idiomatic. The book is well-structured: from simple to complex, with a large number of exercises. The translation from Scala to Kotlin is done well, taking into account the language's features (e.g., the use of extension functions, sealed classes).
Who it is recommended for
The book is a must-read for all Kotlin developers striving for professional growth. It will also be useful for Python programmers interested in functional programming: many ideas (monads, functors) can be implemented in Python using type hints and libraries like returns. However, it should be noted that the book requires a basic knowledge of Kotlin and some mathematical maturity. It may be difficult for programming beginners.
Conclusion
«Functional Programming in Kotlin» is not just a translation, but a full-fledged guide that will teach you to think functionally. We recommend it to everyone who wants to go beyond OOP and master the powerful FP toolkit in a modern language.