Talk in English - US at PHPDetroit Conference 2018
View Slides: https://speakerdeck.com/justinyost/generators-all-about-the-yield-3
Checkout the code: https://github.com/justinyost/las-vegas-generators-talk
Short URL: https://joind.in/talk/7688b (QR-Code (opens in new window))
Generators are a relatively unexplored feature of PHP. Coming about in PHP 5.5, Generators provide for the ability to write Iterator style code without a lot of upfront work. In addition to that Generators provide for some amazing abilities to write coroutines in PHP that we previously didn't have. Generators are at their core a tool to enable us to write code that can solve entire classes of problems that beforehand would have been exceedingly hard to do before hand. Perhaps most importantly, generators are fun to explore.
Comments are closed.
Great progression from the simplest generator through each additional feature. Would be nice if the final coroutine example could fit on one slide--it's tricky to understand.
This was an absolute firehose, but I think the room was having a hard time keeping up with Justin. I spent most of the talk trying to think "where would this be really useful", only to have the talk end on (spoilers) "so, where is this stuff really useful? Well, not many places, to be honest."
Rather than fizzbuzz and counting, even fake user-space code might make the examples more accessible.
I was able to follow well, but I have the advantage of having dealt with much of this in Python, where generators are more of a norm. And despite that, I still learned things about generators in PHP.
What was hard to follow for me was the examples where there was a "yield 'return-val'" mixed with send() calls. It was much clearer to see what was happening with numbers being yielded instead, because it's obvious when "2" and "3" come back, that "1" was lost.