Functional Kotlin

This book is about functional programming features in Kotlin. It first covers the essentials, and then is building on them, it presents important and practical topics like collection processing, scope functions, and DSL usage and creation.


At the beginning of 21st century, Java had dominated commercial programming, and together with this language, Object-Oriented paradigm ruled in our discipline. Many thought, that the holy war between two biggest paradigms was resolved, and then Scala showed us, that they hadn't needed to fight with each other at the first place. A programming language can have both functional and object-oriented features, and they complement each other. This has started a renaissance of functional programming: essential functional programming features have being introduced to many popular languages. Nowadays, most main-stream languages support both functional and object-oriented features, but the problem is that people often still lack knowledge, of how to use them effectively and efficiently.

Who is this book for?

This book is dedicated to developers with a basic experience in using Kotlin, or to developers who read my other book Kotlin for developers: Essential.

What will be covered?

This book concentrates on the functional Kotlin features, including:

  • function types,
  • anonymous functions,
  • lambda expressions,
  • function references,
  • functional interfaces,
  • collection processing functions,
  • sequences,
  • DSL usage and creation,
  • scope functions.

This book is based on a workshop I conduct, and I chose to discuss this topic, that were most important for the attendees.

Marcin Moskała

Marcin Moskała

Marcin Moskala is an experienced developer and Kotlin trainer. He is the founder of the Kt. Academy, an official JetBrains partner for Kotlin trainings, author of the books Effective Kotlin, Kotlin Coroutines and Android Development with Kotlin. He is also the main author of the biggest medium publication about Kotlin and a speaker invited to many programming conferences.

Chapters available as articles

Function references

How do we reference functions in Kotlin, to replace lambda expressions. All functions, including constructors, getters, extensions and more.

Function types

What is a function type, and what less known features it offers.

Collection processing in Kotlin: Basic functions

One of the most useful applications of functional programming is collection processing. Let's learn about essential collection processing functions. That is also a start of a series of articles about functional collection processing functions.

Collection processing in Kotlin: Folding and reducing

Folding stands behind nearly all collection processing functions. fold and reduce are our super agents, we can use whenever we cannot find more specific collection processing function.

Collection processing in Kotlin: Using indices

Just because we use use functional processing function, does not stop us from using indices. Let's learn about withIndex and indexed variants of important functions.

Collection processing in Kotlin: drop and take

How to take the first n elements? Of all except the first n? Let's learn about drop, take, dropLast and takeLast.

Collection processing in Kotlin: Finding, counting, and checking conditions

Let's learn about finding elements, counting those that fulfill a predicate, or checking predicates for all elements.

Collection processing in Kotlin: Grouping elements

How do we group collection elements in Kotlin, and how is that useful in a variety of algorithms.