SlideShare a Scribd company logo
Building an Incredible Machine
With Generators and Pipelines in PHP
by Dan Leech
@dantleech
g
b
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
/**
* @Revs(1000)
* @Iterations(10)
*/
class HashingBench
{
public function benchMd5()
{
md5('hello world');
}
public function benchSha1()
{
sha1('hello world');
}
}
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
No way to interpolate tests
Three Benchmarks
Linear Execution
Linear Execution
Interpolated Execution
The results are now consistently inconsistent
PHPBench will report a high standard deviation, and you will
know to start again.
Instant Comparison
By interpolating tests we can provide faster
feedback to the user
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
Can I do this with Iterators?
Can I do this with Generators?
Generators
PHP 5.5.0
20 June 2013
Generators are Iterators
<?php
$iterator = new ArrayIterator([
‘key1’ => ‘value1’,
‘key2’ => ‘value2’,
]);
foreach ($iterator as $key => $value) {
echo “{$key} {$value}”;
}
AppendIterator
ArrayIterator
CachingIterator
CallbackFilterIterator
DirectoryIterator
EmptyIterator
FilesystemIterator
FilterIterator
AppendIterator
ArrayIterator
CachingIterator
CallbackFilterIterator
DirectoryIterator
EmptyIterator
FilesystemIterator
FilterIterator
GlobIterator
InfiniteIterator
IteratorIterator
LimitIterator
MultipleIterator
← Pseudo-type accepting arrays and Traversable (7.1)
← Cannot implement
<?php
function dump_many(iterable $iterable)
{
foreach ($iterable as $value) {
var_dump($value);
}
}
dump_many(['one', 'two', 'three']);
dump_many(new ArrayObject(['one', 'two', 'three']));
// string(3) "one"
// string(3) "two"
// string(5) "three"
// string(3) "one"
// string(3) "two"
// string(5) "three"
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
class MyAwesomeIterator implements Iterator {
private $myArray;
public function __construct(array $myArray) {
$this->myArray = $myArray;
}
function rewind() {
return reset($this->myArray);
}
function current() {
return current($this->myArray);
}
function key() {
return key($this->myArray);
}
function next() {
return next($this->myArray);
}
function valid() {
return key($this->myArray) !== null;
}
Generators are easy Iterators
That you cannot rewind
But that's OK, because they do cool stuff
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
final class Generator implements Iterator {
function rewind() {}
function valid() {}
function current() {}
function key() {}
function next() {}
function send($value) {}
function throw(Exception $exception) {}
function getReturn() {}
}
final class Generator implements Iterator {
function rewind() {}
function valid() {}
function current() {}
function key() {}
function next() {}
function send($value) {}
function throw(Exception $exception) {}
function getReturn() {}
}
Iterator
final class Generator implements Iterator {
function rewind() {}
function valid() {}
function current() {}
function key() {}
function next() {}
function send($value) {}
function throw(Exception $exception) {}
function getReturn() {}
}
Generator
YIELD
function numbers(): Generator
{
yield "1";
yield "2";
yield "3";
}
foreach (numbers() as $number) {
echo $number;
}
// 123
Yielding control
<?php
function lines($fileName)
{
$h = fopen($fileName, 'r');
$lines = [];
while (false !== $line = fgets($h)) {
$lines[] = $line;
}
fclose($h);
return $lines;
}
foreach (lines() as $line) {
echo $line;
}
Example with standard array
<?php
function lines($fileName)
{
$h = fopen($fileName, 'r');
while (false !== $line = fgets($h)) {
yield $line;
}
fclose($h);
}
foreach (lines() as $line) {
echo $line;
// do something else
Example with generator
Generators make functions interruptible
final class Generator implements Iterator {
function rewind() {}
function valid() {}
function current() {}
function key() {}
function next() {}
function send($value) {}
function throw(Exception $exception) {}
function getReturn() {}
}
Generator
send()
send()
function myGenerator(): Generator
{
$data = yield;
yield $data;
}
echo myGenerator()->send('Goodbye');
// Goodbye
Fast forwards to first yield returns
the sent value
send()
<?php
function echoGenerator(): Generator
{
$data = yield;
$data = yield $data;
}
$generator = echoGenerator();
var_dump($generator->send('Hello'));
var_dump($generator->send('Goodbye'));
var_dump($generator->send('Adios'));
send()
string(5) "Hello"
NULL
NULL
throw()
throw()
function myGenerator(): Generator
{
try {
yield;
} catch (MyException $e) {
echo 'Hello!';
}
}
echo myGenerator()->throw(new MyException());
Exception thrown here
invalid generator
function myGenerator(): Generator
{
try {
yield;
} catch (MyException $e) {
echo 'Hello!';
}
}
$generator = myGenerator();
$generator->next();
echo myGenerator()->throw(new MyException());
Exception thrown here
getReturn()
getReturn
<?php
function hello(): Generator
{
yield 'hello';
yield 'goodbye';
return 'ciao';
}
$generator = hello();
echo $generator->getReturn();
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
PHP Fatal error: Uncaught Exception: Cannot get
return value of a generator that hasn't returned
getReturn
<?php
function hello(): Generator
{
yield 'hello';
yield 'goodbye';
return 'ciao';
}
$generator = hello();
$generator->next()
$generator->next();
echo $generator->getReturn();
// ciao
Generators will not return the return value
Unless you call getReturn()
After the generator has returned
Asynchronous Operations
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
Async Operations
function requestUrl($url): Generator {
$process = new Process("curl -I $url");
$process->start();
while ($process->isRunning()) {
echo $url . "n";
yield;
}
yield $process->getOutput();
}
WARNING: This code is terrible, please do not use it
Async Operations
$generators = [
requestUrl('https://inviqa.com'),
requestUrl('https://bbc.co.uk'),
];
while ($generators) {
foreach ($generators as $i => $gen) {
$result = $gen->current()
if ($result !== false) {
var_dump($result); // success!!!
}
$gen->next();
if ($gen->valid() === false) {
unset($generators[$i]);
}
}
WARNING: This code is terrible, please do not use it
https://www.inviqa.com
https://www.inviqa.com
http://www.bbc.com
http://www.bbc.com
https://www.inviqa.com
http://www.bbc.com
https://www.inviqa.com
http://www.bbc.com
https://www.inviqa.com
http://www.bbc.com
https://www.inviqa.com
http://www.bbc.com
https://www.inviqa.com
http://www.bbc.com
https://www.inviqa.com
http://www.bbc.com
https://www.inviqa.com
http://www.bbc.com
https://www.inviqa.com
http://www.bbc.com
https://www.inviqa.com
string(344) "HTTP/1.1 301 Moved Permanently
Date: Tue, 20 Feb 2018 21:21:23 GMT
Connection: keep-alive
Cache-Control: max-age=3600
Expires: Tue, 20 Feb 2018 22:21:23 GMT
Location: http://inviqa.com/
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-
cgi/beacon/expect-ct"
Server: cloudflare
CF-RAY: 3f0483ebdb3a2d6b-TXL
string(612) "HTTP/1.1 200 OK
Server: Apache
Content-Type: text/html
Expires: Tue, 20 Feb 2018 21:21:32 GMT
Content-Language: en
Etag: "25e4bf9a0519a562c8fb0a6379044365"
X-PAL-Host: pal143.back.live.telhc.local:80
Content-Length: 209756
Date: Tue, 20 Feb 2018 21:21:23 GMT
Connection: keep-alive
Set-Cookie: BBC-
UID=055ac8cca981056306da9a3821c959a1b1d799b4875494361aa037e2fe86c6080curl/7.55.1;
expires=Sat, 19-Feb-22 21:21:23 GMT; path=/; domain=.bbc.com
Cache-Control: private, max-age=60
X-Cache-Action: HIT
X-C"...
Go and look at event loops
AMP
Amp is a non-blocking concurrency
framework for PHP. It provides an event
loop, promises and streams as a base for
asynchronous programming.
Promises in combination with generators
are used to build coroutines, which allow
writing asynchronous code just like
synchronous code, without any callbacks.
https://github.com/amphp/amp
AMP
Amp is a non-blocking concurrency
framework for PHP. It provides an event
loop, promises and streams as a base for
asynchronous programming.
Promises in combination with generators
are used to build coroutines, which allow
writing asynchronous code just like
synchronous code, without any callbacks.
https://github.com/amphp/amp
Infinite Potential
while (true)
<?php
function natural_numbers($number = 1): Generator
{
while (true) {
yield $number++;
}
}
foreach (numbers() as $number) {
echo $number . ' ';
}
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
108 109 110 111 112 113 114 115 116 117 118 ...
The number of iterations is no longer the concern
of the generator
Recursion
function myGenerator(): Generator
{
$count = yield;
while (true) {
$count = $count * 2;
$count = yield $count;
}
}
$generator = myGenerator();
$count = 1;
while (true) {
$count = $generator->send($count);
}
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
Pipelines
A pipeline is a sequence of stages.
Each stage has a specific job to do.
1)Make each program do one thing well. To do a new job, build afresh
rather than complicate old programs by adding new "features".
2)Expect the output of every program to become the input to another, as yet
unknown, program. Don't clutter output with extraneous information. Avoid
stringently columnar or binary input formats. Don't insist on interactive
input.
3)Design and build software, even operating systems, to be tried early,
ideally within weeks. Don't hesitate to throw away the clumsy parts and
rebuild them.
4)Use tools in preference to unskilled help to lighten a programming task,
even if you have to detour to build the tools and expect to throw some of
them out after you've finished using them.
Unix Philosophy
1)Make each program do one thing well. To do a new job, build afresh
rather than complicate old programs by adding new "features".
2)Expect the output of every program to become the input to another, as yet
unknown, program. Don't clutter output with extraneous information. Avoid
stringently columnar or binary input formats. Don't insist on interactive
input.
3)Design and build software, even operating systems, to be tried early,
ideally within weeks. Don't hesitate to throw away the clumsy parts and
rebuild them.
4)Use tools in preference to unskilled help to lighten a programming task,
even if you have to detour to build the tools and expect to throw some of
them out after you've finished using them.
Unix Philosophy
Unix Pipes
$ echo '<?php echo "hello";' | php
hello
This is a simple phraze this is
Spell Checker
$ echo 'This is a a simple phraze this is'
Command
Output
This
is
a
simple
phraze
this
is
Spell Checker
$ echo 'This is a simple phraze this is' |
words
Command
Output
this
is
a
simple
phraze
this
is
Spell Checker
$ echo 'This is a simple phraze' |
words |
lowercase
Command
Output
a
is
is
phraze
simple
this
this
Spell Checker
$ echo 'This is a simple phraze' |
words |
lowercase |
sort
Command
Output
a
is
phraze
simple
this
Spell Checker
$ echo 'This is a simple phraze' |
words |
lowercase |
sort |
unique
Command
Output
phraze
Spell Checker
$ echo 'This is a simple phraze' |
words |
lowercase |
sort |
unique |
mismatch dictionary.txt
Command
Output
That wasn't GNU
Stage GNU
words fmt -1
lowercase tr '[:upper:]' '[:lower:]'
sort sort
unique uniq
mismatch dictionary.txt comm -23 - dictionary.txt
Working together + Specialisation
Pipelines in PHP
Input
Callable
Stage
Output
Stage
Stage
Input
Callable
Callable
Output
Callable
Callable function ($value) { return $value * 2; }
10
20
function ($value) { return $value +1; }
21
function ($value) { return $value * 2; }
42
$pipeline = (new Pipeline)
->pipe(function ($value) {
return $value * 2;
})
->pipe(function ($value) {
return $value +1;
})
->pipe(function ($value) {
return $value * 2;
})
;
$pipeline->process(10);
class TimesTwoStage {
public function __invoke($value) {
return $value * 2;
}
}
class AddOneStage {
public function __invoke($value) {
return $value + 1;
}
}
$pipeline = (new Pipeline)
->pipe(new TimesTwoStage())
->pipe(new AddOneStage())
->pipe(new TimesTwoStage());
$pipeline->process(10);
Stages can be Generators
function Stage1(): Generator
{
$payload = yield;
while (true) {
$data = yield data;
}
}
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
Let's build a thing!
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
Thanks
Blog Posts
●
https://nikic.github.io/2012/12/22/Cooperative-multitasking-using-coroutines-in-PHP.html
●
https://blog.ircmaxell.com/2012/07/what-generators-can-do-for-you.html
● https://speakerdeck.com/chrispitt/cooperative-multitasking-with-generators
– https://www.youtube.com/watch?v=cY8FUhZvK7w
●
https://medium.com/@aaronweatherall/the-pipeline-pattern-for-fun-and-profit-9b5f43a98130
●
https://www.cise.ufl.edu/research/ParallelPatterns/PatternLanguage/AlgorithmStructure/Pipeline.htm
● https://markbakeruk.net/2016/01/19/a-functional-guide-to-cat-herding-with-php-generators/
● http://sergeyzhuk.me/2018/02/15/amp-coroutines/
●
https://medium.com/ifixit-engineering/functional-programming-with-php-generators-837a6c91b0e3
● https://www.entropywins.wtf/blog/2017/10/16/introduction-to-iterators-and-generators-in-php/
●
http://blog.kevingomez.fr/2016/01/20/use-cases-for-php-generators/
Videos
● Cooperative multitasking with Generators:
https://www.youtube.com/watch?v=cY8FUhZvK7w
● Pushing the limits of PHP with React:
https://www.youtube.com/watch?
v=fQxxm4vD8Ok&feature=youtu.be
● Herding Cats: https://vimeo.com/189755262
● What the heck is the event loop anyway?:
https://www.youtube.com/watch?v=8aGhZQkoFbQ
Use Generators NOW!
● Importing Data
● Data providers in PHPUnit (and PHPBench!)
Before
/**
* @dataProvider provideMultiplies
*/
function testMultiplies($v, $m, $expected) {
$result = $this->multiplier->multiply($v, $m);
$this->assertEquals($expected, $result);
}
public function provideMultiplies()
{
return [
'one times one' => [ 1, 1, 1 ],
'two times two' => [ 2, 2, 4 ],
];
}
After
/**
* @dataProvider provideMultiplies
*/
function testMultiplies($v, $m, $expected) {
$result = $this->multiplier->multiply($v, $m);
$this->assertEquals($expected, $result);
}
public function provideMultiplies()
{
yield 'one times one' => [ 1, 1, 1 ];
yield 'two times two' => [ 2, 2, 4 ];
}
● Saved 2 lines of code
● Looks nicer
● Not actually lazy ... but it could be!

More Related Content

PPTX
A Functional Guide to Cat Herding with PHP Generators
PDF
Into the ZF2 Service Manager
PPTX
A Functional Guide to Cat Herding with PHP Generators
PDF
Asynchronous programming done right - Node.js
PPTX
Build Lightweight Web Module
PDF
Python meetup: coroutines, event loops, and non-blocking I/O
PDF
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
PDF
GPars For Beginners
A Functional Guide to Cat Herding with PHP Generators
Into the ZF2 Service Manager
A Functional Guide to Cat Herding with PHP Generators
Asynchronous programming done right - Node.js
Build Lightweight Web Module
Python meetup: coroutines, event loops, and non-blocking I/O
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
GPars For Beginners

What's hot (20)

PDF
IoT Best practices
PDF
Building Testable PHP Applications
PDF
Diving into HHVM Extensions (PHPNW Conference 2015)
PDF
Symfony2 revealed
PDF
Diving into HHVM Extensions (php[tek] 2016)
PDF
PyCon lightning talk on my Toro module for Tornado
PDF
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
PDF
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
PDF
PostgreSQL Procedural Languages: Tips, Tricks and Gotchas
DOCX
VPN Access Runbook
PDF
What's new in PHP 8.0?
PDF
Currying and Partial Function Application (PFA)
PDF
Node Boot Camp
PDF
Advanced functional programing in Swift
PDF
Découvrir dtrace en ligne de commande.
PDF
Creating Lazy stream in CSharp
PDF
Monads in Swift
PDF
OSCON - ES6 metaprogramming unleashed
PDF
RxSwift to Combine
PDF
Workshop 10: ECMAScript 6
IoT Best practices
Building Testable PHP Applications
Diving into HHVM Extensions (PHPNW Conference 2015)
Symfony2 revealed
Diving into HHVM Extensions (php[tek] 2016)
PyCon lightning talk on my Toro module for Tornado
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
PostgreSQL Procedural Languages: Tips, Tricks and Gotchas
VPN Access Runbook
What's new in PHP 8.0?
Currying and Partial Function Application (PFA)
Node Boot Camp
Advanced functional programing in Swift
Découvrir dtrace en ligne de commande.
Creating Lazy stream in CSharp
Monads in Swift
OSCON - ES6 metaprogramming unleashed
RxSwift to Combine
Workshop 10: ECMAScript 6
Ad

Similar to Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin) (20)

ODP
Incredible Machine with Pipelines and Generators
PDF
Generating Power with Yield
PPTX
Electrify your code with PHP Generators
PPTX
Generated Power: PHP 5.5 Generators
PDF
Cryptography in PHP: use cases
PDF
잘 알려지지 않은 Php 코드 활용하기
PDF
ReactPHP
PDF
PHP Generators
PDF
Go from PHP engineer's perspective
PDF
$kernel->infect(): Creating a cryptovirus for Symfony2 apps
PPTX
object oriented programming in PHP & Functions
PDF
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
PDF
Debugging: Rules And Tools - PHPTek 11 Version
PDF
08 Advanced PHP #burningkeyboards
PDF
Gearman - Northeast PHP 2012
PDF
Living With Legacy Code
PPTX
php programming.pptx
ODP
The promise of asynchronous PHP
PDF
international PHP2011_ilia alshanetsky_Hidden Features of PHP
ODP
PHP5.5 is Here
Incredible Machine with Pipelines and Generators
Generating Power with Yield
Electrify your code with PHP Generators
Generated Power: PHP 5.5 Generators
Cryptography in PHP: use cases
잘 알려지지 않은 Php 코드 활용하기
ReactPHP
PHP Generators
Go from PHP engineer's perspective
$kernel->infect(): Creating a cryptovirus for Symfony2 apps
object oriented programming in PHP & Functions
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
Debugging: Rules And Tools - PHPTek 11 Version
08 Advanced PHP #burningkeyboards
Gearman - Northeast PHP 2012
Living With Legacy Code
php programming.pptx
The promise of asynchronous PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHP
PHP5.5 is Here
Ad

More from dantleech (7)

PDF
2019 11-bgphp
PDF
Exploring Async PHP (SF Live Berlin 2019)
ODP
Phpactor and VIM
ODP
A Tale of Three Components
PDF
Boltc CMS - a really quick overview
PDF
Tmux quick intro
PDF
Benchmarking and PHPBench
2019 11-bgphp
Exploring Async PHP (SF Live Berlin 2019)
Phpactor and VIM
A Tale of Three Components
Boltc CMS - a really quick overview
Tmux quick intro
Benchmarking and PHPBench

Recently uploaded (20)

PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
cuic standard and advanced reporting.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Getting Started with Data Integration: FME Form 101
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Electronic commerce courselecture one. Pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Machine learning based COVID-19 study performance prediction
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Big Data Technologies - Introduction.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Approach and Philosophy of On baking technology
Diabetes mellitus diagnosis method based random forest with bat algorithm
cuic standard and advanced reporting.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Getting Started with Data Integration: FME Form 101
A comparative analysis of optical character recognition models for extracting...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Electronic commerce courselecture one. Pdf
MIND Revenue Release Quarter 2 2025 Press Release
Reach Out and Touch Someone: Haptics and Empathic Computing
Machine learning based COVID-19 study performance prediction
Mobile App Security Testing_ A Comprehensive Guide.pdf
Empathic Computing: Creating Shared Understanding
Group 1 Presentation -Planning and Decision Making .pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Big Data Technologies - Introduction.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Spectral efficient network and resource selection model in 5G networks
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Approach and Philosophy of On baking technology

Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)

Editor's Notes

  • #2: In this talk we will briefly discuss a specific problem in PHPBench (a benchmarking tool for PHP) which can be solved through the use of Generators (and pipelines!). We will then explore both topics generally, before combining them into an Incredible Machine in a live coding session.
  • #4: I was on the bench at the beginning of this month. I was wondering what to do Then I remembered that I always intended to make PHPBench better...
  • #6: - Explain better what this does - Why are you doing things with hashes
  • #14: Composition Making a system
  • #15: Iterators rotate
  • #16: Generators can pass values to each other while rotating
  • #20: - Iterators can have state - Get values from a database - Generate values
  • #23: - Iterators can have state - Get values from a database - Generate values
  • #24: Doctrine ORM Example
  • #25: Native PHP array functions counterparts
  • #27: The type hierarchy - Iterable: PHP 7.1 - Pseudo type - array - Traversable: System type - Iterator - Iterator Aggregate
  • #32: Same as passing [1,2,3] to the built in array-iterator (next slide)
  • #35: Control is being passed from the generator to the for loop
  • #40: - What is going to happen here - Value is returned by yield
  • #41: - Value is returned by yield -
  • #43: &amp;lt;REVIEW!!&amp;gt;
  • #44: - Sending signals to the generator (e.g. close file) - ...?
  • #49: Get return allows you to retrieve the value
  • #55: - *PHP is async* - Replace somethingElse (AccessDatabase, concurrent HTTP requests).
  • #56: - *PHP is async* - Replace somethingElse (AccessDatabase, concurrent HTTP requests).
  • #64: Generators can be chained to each other
  • #93: - Tests are interpolated - Instant comparison - View evolution of tests - Timed tests (remember Infinite!)