←back to thread

116 points doekenorg | 2 comments | | HN request time: 0s | source
Show context
Amakanski ◴[] No.44498559[source]
>> This would require a yield to syntax, which doesn't exist.

There is however the 'yield from' statement.

replies(3): >>44498922 #>>44499113 #>>44499996 #
Cyykratahk ◴[] No.44499113[source]
I'd use `yield from` more if I didn't have to re-index arrays before yielding from them:

    function numbers() {
      yield from [1,2,3];
      yield from [4,5,6];
    };
    
    foreach (numbers() as $k => $v) { echo "$k => $v\n"; }
    0 => 1
    1 => 2
    2 => 3
    0 => 4
    1 => 5
    2 => 6
replies(1): >>44499518 #
bvrmn ◴[] No.44499518[source]
PHP generators/iterators is a hot mess. I don't know any other language which forces iterators to output a key for `foreach(... as $key => ...)`.
replies(2): >>44499619 #>>44512570 #
1. Fidelix ◴[] No.44512570[source]
"It's a hot mess" - someone who knows absolutely nothing about what they're talking about.

Typical HN comment about php.

replies(1): >>44539767 #
2. bvrmn ◴[] No.44539767[source]
Defenders of PHP's iterators clearly tasted only carrots.