Generators' week: here we go!
January 19, 2016 —In my opinion, generators are the most striking feature of PHP 5.5. Still, when, during a talk in Nantes in september last year, I asked who in the room was using generators, only a couple of hands were raised. Amongst about 40 people!
Several conversations I’ve had since then lead to ideas like « this seems cool, but do you have a real case for which you used a generator? ». After all, even if it seems nice on paper and in conferences, nothing beats reals-world scenarios!
So, I asked on Twitter if people using generators would like to write about their experience, to share use-cases they met and to show in which real situations using a generator can be helpful, useful, or cool!
Several developpers answered. And, so, here’s the first generators’ week!
- Day 1: (in French) to start things up, Sébastien Rogier uses generators to aggregate some data from several data-sources, on a big CLI-batch, without reaching his servers’
memory_limit
: Cas d’utilisation de yield en PHP - Day 2 : (in English) today, Mark Baker gives us a re-implementation of
array_map()
,array_filter()
andarray_reduce()
that can be used on generators, allowing us to work on data on the fly: A Functional Guide to Cat Herding with PHP Generators - Day 3 : (in English) for this third day, Kévin Gomez shows two use-cases for generators: Use cases for PHP generators
- Day 4 : (in French) this is the fourth day and Florian FERRIERE’s turn to write his Présentation des générateurs
- Day 5 : (in French) for the end of this week, it’s my turn talking about one of my use-cases: Les générateurs, c’est le bien ! Un cas d’usage.
Here are a few other posts, a bit older, which have been recommanded by other people or which I thought about later:
- Yell at yield! and using yield generator with mongodb
- Processing large datasets with Doctrine
- Cooperative multitasking using coroutines
- (in french) An introduction to generators I wrote back in 2012, when PHP 5.5’s release was getting close.
You would like to share your experience, a use-case, about generators? Please, do so!
Or about another subject? Same thing ;-)