Book Image

Functional Kotlin

Book Image

Functional Kotlin

Overview of this book

Functional programming makes your application faster, improves performance, and increases your productivity. Kotlin supports many of the popular and advanced functional features of functional languages. This book will cover the A-Z of functional programming in Kotlin. This book bridges the language gap for Kotlin developers by showing you how to create and consume functional constructs in Kotlin. We also bridge the domain gap by showing how functional constructs can be applied in business scenarios. We’ll take you through lambdas, pattern matching, immutability, and help you develop a deep understanding of the concepts and practices of functional programming. If you want learn to address problems using Recursion, Koltin has support for it as well. You’ll also learn how to use the funKtionale library to perform currying and lazy programming and more. Finally, you’ll learn functional design patterns and techniques that will make you a better programmer.By the end of the book, you will be more confident in your functional programming skills and will be able to apply them while programming in Kotlin.
Table of Contents (22 chapters)
Title Page
Copyright and Credits
Dedication
Packt Upsell
Contributors
Preface
Index

Chapter 10. Functors, Applicatives, and Monads

Functors, applicatives, and monads are among the most searched words related to functional programming, which makes sense if you consider that no-one knows what they mean (not really, there are bright people that know what they're talking about). The confusion about monads, in particular, has become a joke/meme in the programming community:

"A monad is a monoid in the category of endofunctors, what's the problem?"

This quote is fictionally attributed to Philip Wadler by James Iry on his classic blog post, A Brief, Incomplete and Mostly Wrong History of Programming Languages, (http://james-iry.blogspot.co.uk/2009/05/brief-incomplete-and-mostly-wrong.html).

In this chapter, we will cover the following topics:

  • Functors
  • Options, lists, and functions as functors
  • Monads
  • Applicatives