On Wed, Aug 22, 2012 at 10:21 AM, Lester Caine <les...@lsces.co.uk> wrote:
> Morgan L. Owens wrote: > >> As I wrote in an earlier post: >> >> On 2012-08-09 15:30, Morgan L. Owens wrote: >> > I for one am lazy, and would much prefer writing: >> > <?php >> > function append_iterator($first, $second) >> > { >> > foreach($first as $i) >> > { >> > yield $i; >> > } >> > foreach($second as $i) >> > { >> > yield $i; >> > } >> > } >> > ?> >> > > Morgan > > I think THIS is an nice example of why I am having a problem with the > concept. > EXACTLY what is yield doing here? > If this was an SQL procedure, then at the first yield (suspend in SQL), > the procedure returns the values and the external process uses them. Next > call to the procedure returns the next set of values. > In your example you have TWO 'suspend' points, and this is what is making > things confusing for me. SO is this returning every $first value followed > by every $second ? > Without some better explanation of how the work flows, reading and > understanding even what the above example means is a problem? > The answer may be simple but people telling me 'just because you don't > understand is no reason to reject them' is just irritating. I'd LIKE to > understand what they are intended to provide but I'm still just not getting > it as hopefully the explanation here highlights? > I'm sure I'm not alone here? > > if you are a consumer of a generator, you don't have to understand the underlying process, as it 'just works'. you don't have to know about how a specific iterator or generator works internally as long as they are implementing the iterator and countable interface you can just use them as arrays. of course if you want to write your own generators, you have to understand how those work, but I think that after this much discussion and explanations, we can't really help you with that. why is it matter that there is two place in the function body with yield? you can have methods with two break, or continue. does that also confuse you? it doesn't make a difference, if you yield only once, and put that into a loop, or copy paste the yield line ten times. yield always does the same thing, pass the execution to the caller. -- Ferenc Kovács @Tyr43l - http://tyrael.hu