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

Domain Driven Design


We can use a layered domain driven architecture as a tool for structuring our large-scale functional programs in a modular and composable manner. This architecture helps us visualize the separate application concerns and enables us to write Go code whose source code dependencies only point inwards.

All references, that is, import statements must point inwards. An import domain statement can be found in all other packages. Import use cases can be found in the interfaces and infrastructure packages. Import interfaces can be found in the infrastructure package and no package (except the import_test package that we'll cover later) is permitted to import the infrastructure package:

The preceding diagram is somewhat of a paradox. The more we move inwards, the higher level our software becomes. The domain entities are high-level concepts. Whereas, the more we move outwards, the more low-level our software is. The infrastructure is where we interact with the filesystem, cloud...