Practical FP in Scala: A hands-on approach
Practical FP in Scala: A hands-on approach
About the Book
Practical FP in Scala: A hands-on approach, is a book for intermediate to advanced Scala developers. Aimed at those who understand functional effects, referential transparency and the benefits of functional programming to some extent but who are missing some pieces to put all these concepts together to build a large application in a time-constrained manner.
Throughout the chapters we will design, architect and develop a complete stateful application serving an API via HTTP, accessing a database and dealing with cached data, using the best practices and best functional libraries available in the Cats ecosystem.
You will also learn about common design patterns such as managing state, error handling and anti-patterns, all accompanied by clear examples. Furthermore, at the end of the book, we will dive into some advanced concepts such as MTL, Classy Optics and Typeclass derivation.
The book is supplemented by two Scala projects:
- Shopping Cart application: https://github.com/gvolpe/pfps-shopping-cart
- Standalone examples: https://github.com/gvolpe/pfps-examples
Got some feedback? Please email the author here: pfpscala at gmail dot com.
- Dependency version
How to read this book
- Conventions used in this book
1. Chapter 1: Shopping Cart project
1.1 Business requirements
- 1.1.1 Third-party Payments API
- 1.1.2 Identifying the domain
- 1.1.3 Identifying Http endpoints
- 1.2 Architecture
1.3 Technical stack
- 1.3.1 A note on Cats Effect
- 1.1 Business requirements
2. Chapter 2: Design patterns
2.1 Strongly-typed functions
- 2.1.1 Value classes
- 2.1.2 Newtypes
- 2.1.3 Refinement types
2.2 Encapsulating state
- 2.2.1 In-memory counter
2.3 Sequential vs concurrent state
- 2.3.1 State Monad
- 2.3.2 Atomic Ref
2.4 Shared state
- 2.4.1 Regions of sharing
- 2.4.2 Leaky state
- 2.5.1 Seq: a base trait for sequences
- 2.5.2 About Monad Transformers
2.6 Error handling
- 2.6.1 MonadError and ApplicativeError
- 2.6.2 Either Monad
- 2.6.3 Classy prisms
- 2.1 Strongly-typed functions
3. Chapter 3: Tagless final encoding
- 3.1.1 Naming conventions
- 3.2.1 Building interpreters
- 3.3 Programs
3.4 Implicit vs explicit parameters
- 3.4.1 Achieving modularity
- 3.4.2 Implicit convenience
- 3.1 Algebras
4. Chapter 4: Business logic
- 4.1 Identifying algebras
- 4.2 Data access and storage
4.3 Defining programs
- 4.3.1 Checkout
- 4.3.2 Retrying effects
5. Chapter 5: HTTP layer
- 5.1 A server is a function
- 5.2 HTTP Routes #1
- 5.3.1 JWT Auth
- 5.4 HTTP Routes #2
- 5.5 Composing routes
- 5.6.1 Compositionality
- 5.7 Running server
5.8 Entity codecs
- 5.8.1 JSON codecs
- 5.8.2 Validation
5.9 HTTP Client
- 5.9.1 Payment client
- 5.9.2 Creating a client
6. Chapter 6: Persistent layer
6.1 Skunk & Doobie
- 6.1.1 Session Pool
- 6.1.2 Queries
- 6.1.3 Commands
- 6.1.4 Interpreters
- 6.1.5 Streaming & Pagination
6.2 Redis for Cats
- 6.2.1 Connection
- 6.2.2 Interpreters
- 6.3 Blocking operations
- 6.4 Health check
- 6.1 Skunk & Doobie
7. Chapter 7: Testing
- 7.1 Functional test suite
- 7.2 Generators
7.3 Business logic
- 7.3.1 Happy path
- 7.3.2 Empty cart
- 7.3.3 Unreachable payment client
- 7.3.4 Recovering payment client
- 7.3.5 Failing orders
- 7.3.6 Failing cart deletion
- 7.4 Http routes
7.5 Integration tests
- 7.5.1 Resource allocation
- 7.5.2 Postgres
- 7.5.3 Redis
8. Chapter 8: Assembly
- 8.1 Logging
- 8.2 Configuration
- 8.3 Modules
- 8.4 Resources
- 8.5 Main
9. Chapter 9: Deploying
9.1 Docker image
- 9.1.1 Optimizing image
- 9.1.2 Run it locally
9.2 Continuous Integration
- 9.2.1 Dependencies
- 9.2.2 CI build
- 9.2.3 Furthermore
- 9.3 Summary
- 9.1 Docker image
10. Chapter 10: Advanced techniques
- 10.1 Tagless Final plugin
10.2 MTL (Monad Transformers Library)
- 10.2.1 Managing state
- 10.2.2 Accessing context
10.3 Classy optics
- 10.3.1 Lenses
- 10.3.2 Prisms
- 10.3.3 Classy lenses
- 10.3.4 Classy prisms
10.4 Typeclass derivation
- 10.4.1 Kinds
- 10.4.2 Concrete types
- 10.4.3 Higher-kinded types
- 10.4.4 Higher-order functors
10.5 Effectful streams
- 10.5.1 Concurrency
- 10.5.2 Resource safety
- 10.5.3 Interruption
The Leanpub 45-day 100% Happiness Guarantee
Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers), EPUB (for phones and tablets) and MOBI (for Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
C++20 is the next big C++ standard after C++11. As C++11 did it, C++20 changes the way we program modern C++. This change is, in particular, due to the big four of C++20: ranges, coroutines, concepts, and modules.
The book is almost daily updated. These incremental updates ease my interaction with the proofreaders.
A Guide to Artificial Intelligence in HealthcareDr. Bertalan Mesko
Can we stay human in the age of A.I.? To go even further, can we grow in humanity, can we shape a more humane, more equitable and sustainable healthcare? This e-book aims to prepare healthcare and medical professionals for the era of human-machine collaboration. Read our guide to understanding, anticipating and controlling artificial intelligence.
Atomic KotlinBruce Eckel and Svetlana Isakova
For both beginning and experienced programmers! From the author of the multi-award-winning Thinking in C++ and Thinking in Java together with a member of the Kotlin language team comes a book that breaks the concepts into small, easy-to-digest "atoms," along with exercises supported by hints and solutions directly inside IntelliJ IDEA!
Introducing EventStormingAlberto Brandolini
The deepest tutorial and explanation about EventStorming, straight from the inventor.
C++ Best PracticesJason Turner
Level up your C++, get the tools working for you, eliminate common problems, and move on to more exciting things!
Ansible for DevOpsJeff Geerling
Ansible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
Everyday Rails - RSpecによるRailsテスト入門Junichi Ito (伊藤淳一), AKIMOTO Toshiharu, 魚振江, and Aaron Sumner
RSpecを使ってRailsアプリケーションに信頼性の高いテストを書く実践的なアドバイスを提供します。詳細で丁寧な説明は本書のオリジナルコンテンツです。また、説明には実際に動かせるサンプルアプリケーションも使用します。本書は2017年版にアップデートされ、RSpec 3.6やRails 5.1といった新しい環境に対応しています！さあ、自信をもってテストできるようになりましょう！
The Hundred-Page Machine Learning BookAndriy Burkov
Everything you really need to know in Machine Learning in a hundred pages.
Composing SoftwareEric Elliott
All software design is composition: the act of breaking complex problems down into smaller problems and composing those solutions. Most developers have a limited understanding of compositional techniques. It's time for that to change.
R Programming for Data ScienceRoger D. Peng
This book brings the fundamentals of R programming to you, using the same material developed as part of the industry-leading Johns Hopkins Data Science Specialization. The skills taught in this book will lay the foundation for you to begin your journey learning data science. Printed copies of this book are available through Lulu.
Software Architecture for Developers: Volumes 1 & 2 - Technical leadership and communication
2 Books"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before...
All the Books of The Medical Futurist
6 BooksWe put together the most popular books from The Medical Futurist to provide a clear picture about the major trends shaping the future of medicine and healthcare. Digital health technologies, artificial intelligence, the future of 20 medical specialties, big pharma, data privacy, digital health investments and how technology giants such as Amazon...
Cisco CCNA 200-301 Complet
4 BooksCe lot comprend les quatre volumes du guide préparation à l'examen de certification Cisco CCNA 200-301.
Linux Administration Complet
4 BooksCe lot comprend les quatre volumes du Guide Linux Administration :Linux Administration, Volume 1, Administration fondamentale : Guide pratique de préparation aux examens de certification LPIC 1, Linux Essentials, RHCSA et LFCS. Administration fondamentale. Introduction à Linux. Le Shell. Traitement du texte. Arborescence de fichiers. Sécurité...
Learn Git, Bash, and Terraform the Hard Way
3 BooksLearn Git, Bash and Terraform using the Hard Way method.These technologies are essential tools in the DevOps armoury. These books walk you through their features and subtleties in a simple, gradual way that reinforces learning rather than baffling you with theory.
3 BooksBuy every PowerShell book from Adam Bertram at a 20% discount!
Software Architecture and Beautiful APIs
2 BooksThere is no better way to learn how to design good APIs than to look at many existing examples, complementing the Software Architecture theory on API design.
9 Books-Bundle: Shut Up and Code!
9 Books"Shut up and code." Laughter in the audience. The hacker had just plugged in his notebook and started sharing his screen to present his super-smart Python script. "Shut up and code" The letters written in a white literal coding font on black background was the hackers' home screen background mantra. At the time, I was a first-year computer...
CCDE Practical Studies (All labs)
3 BooksCCDE lab
Modern C++ by Nicolai Josuttis