Functional Programming in PHP with Practical Techniques

A functional approach promotes code reuse, simplifies testing, and results in concise, understandable code. This book demonstrates how PHP can be used as a functional language, allowing you to learn various functional techniques for writing maintainable and readable code. After a brief introduction to functional programming, we dive into code examples to help you apply what you've learned. We'll cover monads, memoization, and property-based testing. You'll learn to leverage the modularity of functions while writing functional PHP code. The tips and best practices in this book will enable you to write more efficient code with fewer bugs. You'll enhance performance and address common loop issues. By the end of the book, you'll master new techniques for any codebase, new or legacy.
What You Will Learn:
- Declare functions/callables and manipulate them
- Write pure functions for robust, testable code
- Compose functions using various techniques
- Find readable solutions to common issues with a functional approach
- Optimize performance with laziness, memoization, and parallelization
- Build application business logic with the functional paradigm
- Test functional code and speed up test runs using parallel testing
- Understand the impact and limitations of functional programming in PHP
Table of Contents:
- Thinking Functionally in PHP
- Introduction
- Which PHP version to use?
- Hello FP
- Declarative coding
- Designing for immutability and statelessness
- Pure functions fix side effects
- Referential Transparency
- Functional decomposition
- What is functional programming?
- Higher-order PHP’s first-class, higher-order functions
- Using containers to improve your APIs
- Closures
- Functional vs Object-Oriented
- Summary Table
- Point-free Data Flows and currying
- Error handling with Monads
- React: The Promise Monad
- Reactive Programming in PHP
- Functional Domain Modeling
- Object-oriented in the large, functional in the small
epub 文件大小:1.25MB