Conversation started Feb 18, 2015 at 15:12.
user895378
Feb 18, 2015 15:12
@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 ...
@rdlowrey Return with value is something that would be added in conjunction with coroutine calls (yield from)
user895378
I see. That makes sense.
posted on February 18, 2015 by rdlowrey

- 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...

Feb 18, 2015 15:14
Because then the return value would have a meaningful use in syntax, like $ret = yield* foo();
user895378
So I wouldn't have to do the hacky things that @Feed's just reported about ;)
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.
Feb 18, 2015 15:19
throw new GeneratorDoneException($value);
:-P (totally kidding btw)
user895378
hehe
user895378
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.
@rdlowrey Yeah, I use a wrapper object instead, but same idea ^^
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 think we need a website that lets you build an allowed/disallowed conversoin map for type hints easily.
Feb 18, 2015 15:23
@rdlowrey return is like the final yielded value yeah?
user895378
@LeviMorrison That's what I used to do.
user895378
3 mins ago, by rdlowrey
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.
@rdlowrey Maybe you want to make a small RFC for getReturn()? ^^
user895378
@NikiC I wouldn't mind doing the RFC. The implementation would be up to you if you're interested :)
implementation shouldn't be an issue
user895378
Feb 18, 2015 15:26
Okay. I'll write up an RFC in the next couple of days and get feedback.
cool
 
Conversation ended Feb 18, 2015 at 15:26.