I have various scenarios in loops where I would 'peek' or 'skip' ahead while iterating through items for processing.
One scenario is I'm enumerating through lines of a file, and there is a 'continuation' character at the end of a line indicating to combine the next line with the current line. If I'm simply looping that isn't too hard, I can just read the next line, and bump my counter/index.
It isn't as obvious is the pattern for doing this with my iterator. I effectively want to consume the next line(s) without exiting my closure. But I'm not even sure if that is possible. Are there any good design pattern for this iteration pattern using a closure, so I don't have to resort to a less groovy loop? Is it perhaps a form of iterator with some stack for pushing/popping items for processing?