Book Image

Learning Functional Programming in Go

By : Lex Sheehan
Book Image

Learning Functional Programming in Go

By: Lex Sheehan

Overview of this book

Lex Sheehan begins slowly, using easy-to-understand illustrations and working Go code to teach core functional programming (FP) principles such as referential transparency, laziness, recursion, currying, and chaining continuations. This book is a tutorial for programmers looking to learn FP and apply it to write better code. Lex guides readers from basic techniques to advanced topics in a logical, concise, and clear progression. The book is divided into four modules. The first module explains the functional style of programming: pure functional programming, manipulating collections, and using higher-order functions. In the second module, you will learn design patterns that you can use to build FP-style applications. In the next module, you will learn FP techniques that you can use to improve your API signatures, increase performance, and build better cloud-native applications. The last module covers Category Theory, Functors, Monoids, Monads, Type classes and Generics. By the end of the book, you will be adept at building applications the FP way.
Table of Contents (21 chapters)
Title Page
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
Index

Summary


When testing pure functions, we simply pass input arguments and verify the results. There is no environment or context to set up. There is no need for stubs or mocks. There are no side effects. Testing could not be easier.

Pure functions can be parallelized for performance gains in a horizontally scaled, multi-CPU environment. However, given that Go has not yet been optimized to support pure functional programming, a pure FP implementation in Go might not meet our performance requirements. We won't let that hinder us from leveraging Go's many effective non-pure functional programming techniques. We've already seen how we can gain performance by adding caching logic and leveraging Go's concurrency features. There are many functional patterns that we can use, and we'll soon see how. We'll also see how we can leverage them to meet stringent performance requirements.

In the next chapter, you'll learn about high-order functions as we explore different ways to manipulate collections using FP programming techniques.