@NikiC Am I correct to assume PHP generators can't have non-empty returns (in the way a javascript generator does) because they're actually objects and wouldn't play nice with the existing internal semantics for return? Is it an implementational complexity issue or is it that something like Generator::getReturn() would just be weird and not applicable when Generator::valid()?
user895378
(sorry for asking like ten questions in one there)
user895378
I'm just interested in your thought process with regard to Generator and return ...
- Added `Reactor::coroutine()` method - Added `Amp\coroutine()` function - `YieldCommands` "enum" constant class removed -- yield keys now live in the reactor class - New optional `"coroutine"` yield key for self-documenting generator yields...
Of course one could also have it separately with the Generator::getReturn() you suggested, but it's probably not terribly useful without the yield* operator
but it would already be useful in some cases ...
hm, maybe we should add that independently from coroutine delegation
user895378
Right now I just fake it when resolving coroutines internally. If a generator does this I store it as the "return value" from that generator:
user895378
yield "return" => 42;
user895378
But it would be nice to have some standard way to access the "result" of a generator without resorting to key hacks.
I used to just say, "whatever the last thing is that the generator yielded is the 'return' value" but that was too magical and ambiguous. So now I only assign "return" values if that key is explicitly yielded.
so, I've got her proposal mostly fixed up from a code perspective (really tiny diff). using declare(strict_types=1), but must be the first line in the file.
I used to just say, "whatever the last thing is that the generator yielded is the 'return' value" but that was too magical and ambiguous. So now I only assign "return" values if that key is explicitly yielded.