Functional PHP

Uncover the secrets of functional programming with PHP to ensure your applications are as great as they can be

Functional PHP

This ebook is included in a Mapt subscription
Gilles Crettenand

Uncover the secrets of functional programming with PHP to ensure your applications are as great as they can be
$10.00
$44.99
RRP $35.99
RRP $44.99
eBook
Print + eBook
Access every Packt eBook & Video for just $100
 
  • 4,000+ eBooks & Videos
  • 40+ New titles a month
  • 1 Free eBook/Video to keep every month
Find Out More
 
Preview in Mapt

Book Details

ISBN 139781785880322
Paperback342 pages

Book Description

A functional approach encourages code reuse, greatly simplifies testing, and results in code that is concise and easy to understand. This book will demonstrate how PHP can also be used as a functional language, letting you learn about various function techniques to write maintainable and readable code.

After a quick introduction to functional programming, we will dive right in with code examples so you can get the most of what you’ve just learned. We will go further with monads, memoization, and property-based testing. You will learn how to make use of modularity of function while writing functional PHP code.

Through the tips and best practices in this book, you’ll be able to do more with less code and reduce bugs in your applications. Not only will you be able to boost your performance, but you will also find out how to eliminate common loop problems. By the end of the book, you will know a wide variety of new techniques that you can use on any new or legacy codebase.

Table of Contents

Chapter 1: Functions as First Class Citizens in PHP
Before we begin
Functions and methods
PHP 7 scalar type hints
Anonymous functions
Closures
Using objects as functions
The Closure class
Higher-order functions
What is a callable?
Summary
Chapter 2: Pure Functions, Referential Transparency, and Immutability
Two sets of input and output
Pure functions
Immutability
Referential transparency
PHP in all that?
Summary
Chapter 3: Functional Basis in PHP
General advice
The map function
The filter function
The fold or reduce function
Convolution or zip
Recursion
Exceptions
Alternatives to exceptions
The Option/Maybe and Either types
Libraries
Summary
Chapter 4: Composing Functions
Composing functions
Partial application
Currying
Parameter order matters a lot!
Using composition to solve real issues
Summary
Chapter 5: Functors, Applicatives, and Monads
Functors
Applicative functors
Monoids
Monads
Further reading
Summary
Chapter 6: Real-Life Monads
Monadic helper methods
Maybe and Either monads
List monad
Writer monad
Reader monad
State monad
IO monad
Summary
Chapter 7: Functional Techniques and Topics
Type systems
Point-free style
Using const for functions
Recursion, stack overflows, and trampolines
Pattern matching
Type classes
Algebraic structures and category theory
Monad transformers
Lenses
Summary
Chapter 8: Testing
Testing vocabulary
Testing pure functions
Speeding up using parallelization
Property-based testing
Summary
Chapter 9: Performance Efficiency
Performance impact
Memoization
Parallelization of computation
Summary
Chapter 10: PHP Frameworks and FP
Symfony
Laravel
Drupal
WordPress
Summary
Chapter 11: Designing a Functional Application
Architecture of a purely functional application
From Functional Reactive Animation to Functional Reactive Programming
ReactiveX primer
RxPHP
Summary
Chapter 12: What Are We Talking about When We Talk about Functional Programming
What is functional programming all about?
Why is functional programming the future of software development?
A quick history of the functional world
Functional jargon

What You Will Learn

  • Declare functions/callables and find out how to manipulate and call them
  • Write pure functions to get more robust code that can be easily tested
  • Learn to compose function using various techniques
  • Use a functional approach to find readable solutions to common issues
  • Utilize performance optimization techniques such as laziness, memorization, and parallelization
  • Build the business logic of applications with the functional paradigm
  • Test functional code and know how to speed up test runs using parallel testing
  • Understand the impact and limitation of functional programming in PHP

Authors

Table of Contents

Chapter 1: Functions as First Class Citizens in PHP
Before we begin
Functions and methods
PHP 7 scalar type hints
Anonymous functions
Closures
Using objects as functions
The Closure class
Higher-order functions
What is a callable?
Summary
Chapter 2: Pure Functions, Referential Transparency, and Immutability
Two sets of input and output
Pure functions
Immutability
Referential transparency
PHP in all that?
Summary
Chapter 3: Functional Basis in PHP
General advice
The map function
The filter function
The fold or reduce function
Convolution or zip
Recursion
Exceptions
Alternatives to exceptions
The Option/Maybe and Either types
Libraries
Summary
Chapter 4: Composing Functions
Composing functions
Partial application
Currying
Parameter order matters a lot!
Using composition to solve real issues
Summary
Chapter 5: Functors, Applicatives, and Monads
Functors
Applicative functors
Monoids
Monads
Further reading
Summary
Chapter 6: Real-Life Monads
Monadic helper methods
Maybe and Either monads
List monad
Writer monad
Reader monad
State monad
IO monad
Summary
Chapter 7: Functional Techniques and Topics
Type systems
Point-free style
Using const for functions
Recursion, stack overflows, and trampolines
Pattern matching
Type classes
Algebraic structures and category theory
Monad transformers
Lenses
Summary
Chapter 8: Testing
Testing vocabulary
Testing pure functions
Speeding up using parallelization
Property-based testing
Summary
Chapter 9: Performance Efficiency
Performance impact
Memoization
Parallelization of computation
Summary
Chapter 10: PHP Frameworks and FP
Symfony
Laravel
Drupal
WordPress
Summary
Chapter 11: Designing a Functional Application
Architecture of a purely functional application
From Functional Reactive Animation to Functional Reactive Programming
ReactiveX primer
RxPHP
Summary
Chapter 12: What Are We Talking about When We Talk about Functional Programming
What is functional programming all about?
Why is functional programming the future of software development?
A quick history of the functional world
Functional jargon

Book Details

ISBN 139781785880322
Paperback342 pages
Read More

Read More Reviews