Generators: All About the Yield

Justin Yost (27.Jul.2018 at 11:15, 45 min)
Talk at PHPDetroit Conference 2018 (English - US)

Rating: 4 of 5

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.

Who are you?

Claim talk

Talk claims have been moved to the new site.

Please login to the new site to claim your talk

Comments closed.


Rating: 4 of 5

27.Jul.2018 at 13:05 by Philip Sharp (62 comments) via Web2 LIVE

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.

Rating: 4 of 5

27.Jul.2018 at 14:27 by Steve Grunwell (135 comments) via Web2 LIVE

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.

Rating: 4 of 5

27.Jul.2018 at 21:16 by SapphirePaw (Chad) (10 comments) via Web2 LIVE

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.

© 2019