Never write a
loop again.

Never write another
loop again.

Learn how to craft simple, elegant code that's a pleasure to write and a joy to maintain.

"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.

What's Inside

158-page Book

No introduction, personal anecdotes or stories about my childhood. Just real-world, practical refactoring content, right from page one.

4 Hours of Video

Every refactoring example from the book covered in even more depth, as well as three additional advanced tutorials, making up almost 2 hours of content on their own.

Exercises

A comprehensive set of 25 exercises in the form of unit tests, to practice your chops and make sure you have these patterns under your fingers.

Real Application Code

A copy of the entire Nitpick CI codebase, a production Laravel application that lives and breathes collection pipelines.

“I wrote the library used in this book, and I still learned dozens of tricks that have improved my code. This is the definitive resource for programming with collections.”

Taylor Otwell

Creator of Laravel

Watch a Screencast

Refactoring to Collections includes over 4 hours of screencasts, covering 16 different refactorings that are broken down into 27 videos.

“Adam's use of real-world examples for the more confusing collection transformations makes them approachable for anyone. I cannot recommend Refactoring to Collections enough.”

Matthew Machuga

Senior Developer at Think Through Math

Table of Contents

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 16 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.

A Bit of Theory

  • Imperative vs. Declarative Programming
  • Higher Order Functions
  • Noticing Patterns
  • Functional Building Blocks
  • Reimplementing Each
  • Reimplementing Map
  • Reimplementing Filter
  • Reimplementing Reduce
  • Transforming Data
  • Thinking in Steps
  • The Problem with Primitives
  • Arrays as Objects
  • Introducing Collections
  • A Note on Mutability
  • Quacking Like... an Array?
  • The Golden Rule of Collection Programming

A Lot of Practice

  • Pricing Lamps and Wallets
  • CSV Surgery 101
  • Binary to Decimal
  • What's Your GitHub Score?
  • Formatting a Pull Request Comment
  • Stealing Mail
  • Choosing a Syntax Handler
  • Tagging on the Fly
  • Nitpicking a Pull Request
  • Comparing Monthly Revenue
  • Building a Lookup Table New!
  • Transposing Form Input
  • Ranking a Competition
  • Comparing DNA Strands Screencast exclusive
  • Building a Table of Contents Screencast exclusive
  • Highlighting Code Blocks Screencast exclusive

What People Are Saying

Get a Free Sample

Get a peek at the content. Enter your email address and I'll send you a sample PDF containing a chapter of fundamentals, as well as a refactoring from the second half of the book.

“After reading this book, every loop is now an opportunity to write cleaner, more expressive code. Adam does a marvelous job of unpacking this topic in simple terms. Even better, he provides more examples than you can shake a stick at. So good!”

Jonathan Reinink

PHP League Contributor

Get Refactoring to Collections

Choose the package that works for you.

The Complete Reference Package

The Complete Reference Package

  • The source code to Nitpick CI, a production Laravel application that makes heavy use of collection pipelines
  • Over 4 hours of screencasts, covering all of the book examples + 3 additional advanced tutorials
  • The 158-page book in PDF format
  • Comprehensive set of exercises
Buy Now $249 $179
The Premium Training Package

The Premium Training Package

  • Over 4 hours of screencasts, covering all of the book examples + 3 additional advanced tutorials
  • The 158-page book in PDF format
  • Comprehensive set of exercises
Buy Now $119 $79 Buy for your Team From $199
The Bare Essentials

The Bare Essentials

  • The 158-page book in PDF format
  • Comprehensive set of exercises
Buy Now $39

About the Author

Hey! I'm @adamwathan, senior web application developer, host of Full Stack Radio, and creator of Nitpick CI.

I teach everything I know on my blog, through screencasts, and at conferences around the world.

Frequently Asked Questions

I don't use Laravel, will this product still be useful to me?

100% absolutely yes! All of the principles in this book are not only cross-framework, they are even cross language. Everything you learn from "Refactoring to Collections" will help you write better code everywhere you go.

What content is included in the screencasts that's not included in the book?

The screencasts cover all of the refactorings from the book, plus 3 additional problems that aren't included in the book. The screencast-exclusive examples are "Comparing DNA Strands", "Building a Table of Contents", and "Highlighting Code Blocks."

The three additional examples are really advanced problems, and make up well over an hour of content. You'll learn a ton from those examples!

Can I purchase multiple licenses for my team at a reduced price?

Yes! Click here to check out the team licensing packages. You can buy licenses of the Premium Training Package for teams of up to 5, 10, or 20 depending on what fits your needs.

What am I allowed to do with the Nitpick codebase?

The Nitpick codebase is provided for educational purposes only. This means it's not okay to host a copy of the app anywhere, distribute the code online, etc.

Is the book available in ePub or mobi formats?

Right now the book is only available in PDF format. I'm right in the middle of polishing a responsive HTML version, and then I plan to look into adding ePub and mobi. Anyone who purchases the book will receive any new formats as soon as they're ready.

The reason for starting with PDF is that I wanted to do a lot of somewhat fancy formatting in the book to make the code samples easy to follow. HTML and PDF made this easy, but I'm still unsure how well I'm going to be able to translate it to more restrictive formats like ePub and mobi.

I have another question!

Sure! Shoot me an email at adam.wathan@gmail.com and let's chat!

© 2016 Adam Wathan. All Rights Reserved.

Proudly hosted with DigitalOcean.