"Refactoring to Collections" is a book and video course that teaches you how to apply functional programming principles to write clean, maintainable PHP.
Learn how to use collection pipelines to break down ugly, complex functions into a series of simple transformations, free of loops, complex conditionals, and temporary variables.
The first section of the book focuses on teaching you the theory and fundamentals you need to to start applying functional programming principles to your code.
You'll learn about the difference between imperative and declarative code, how to use higher order functions to remove duplication, and how to reimplement fundamental operations like map, reduce, and filter from first principles.
The second section of the book and the companion screencasts are a deep dive into problem solving with Laravel's Collection library.
Through 15 in-depth examples, we walk through everything from beginner to expert level problems, using advanced operations like zip and transpose, and even extending the library with our own custom transformations.
ZIP with exercises: https://mega.nz/#!eNNTDC5A!IsIxrnFWehtGXqLmMBE4OrUWua4tpc6471X4B2qtJv8
Author(s): Adam Wathan
Year: 2016
Language: English
Pages: 158
Tags: php
Contents......Page 3
Imperative Programming......Page 7
Higher Order Functions......Page 9
Noticing Patterns......Page 10
Each......Page 15
Map......Page 17
Map vs. Each......Page 18
Filter......Page 19
Reject......Page 21
Reduce......Page 23
With Great Power......Page 30
Transforming Data......Page 31
Thinking in Steps......Page 33
The Problem with Primitives......Page 35
Arrays as Objects......Page 37
Introducing Collections......Page 38
A Note on Mutability......Page 40
Quacking Like... an Array?......Page 42
ArrayAccess......Page 43
Countable......Page 45
IteratorAggregate......Page 47
The Golden Rule of Collection Programming......Page 49
A Lot of Practice......Page 51
Pricing Lamps and Wallets......Page 52
Replace Conditional with Filter......Page 54
Replace || with Contains......Page 55
Reduce to Sum......Page 56
Replace Nested Loop with FlatMap......Page 58
Plucking for Fun and Profit......Page 61
CSV Surgery 101......Page 62
Everything is Better as a Collection......Page 65
Using a For Loop......Page 67
Breaking It Down......Page 68
Reversing the Collection......Page 69
Mapping with Keys......Page 70
What's Your GitHub Score?......Page 72
Loops and Conditionals......Page 73
Replace Collecting Loop with Pluck......Page 74
Extract Score Conversion with Map......Page 76
Replace Switch with Lookup Table......Page 77
Associative Collections......Page 79
Extracting Helper Functions......Page 82
Encapsulating in a Class......Page 83
Formatting a Pull Request Comment......Page 86
Map and Implode......Page 87
Stealing Mail......Page 88
Replace Nested Check with Contains......Page 90
Contains as a Higher Order Function......Page 91
Choosing a Syntax Handler......Page 94
Looking for a Match......Page 95
Getting the Right Checker......Page 96
Replace Iteration with First......Page 97
Providing a Default......Page 98
The Null Checker......Page 100
Tagging on the Fly......Page 104
Extracting the Loop......Page 105
Normalizing with Map......Page 107
Nitpicking a Pull Request......Page 109
A Fork in the Code......Page 110
Learning from Smalltalk......Page 111
Collection Macros......Page 113
Chainable Conditions......Page 114
Comparing Monthly Revenue......Page 117
Matching on Index......Page 118
Using Zip to Compare......Page 119
Building a Lookup Table......Page 121
PHP's Array Identity Crisis......Page 122
A Reusable Abstraction......Page 123
The toAssoc Macro......Page 124
Mapping to Pairs......Page 125
Transposing Form Input......Page 127
Quick and Dirty......Page 131
Identifying a Need......Page 132
Introducing Transpose......Page 134
Transpose in Practice......Page 136
Ranking a Competition......Page 138
Zipping-in the Ranks......Page 140
Dealing with Ties......Page 141
Grouping by Score......Page 142
Adjusting the Ranks......Page 145
Collapse and Sort......Page 148
Cleaning Up......Page 150
Grouping Operations......Page 153
Breaking the Chain......Page 154
The Pipe Macro......Page 155
Afterword......Page 158