Combining "chunkBy" and "until" algorithms

Jacob Carlborg via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Nov 4 01:04:12 PDT 2016


I have a file with a bunch of lines I want to process. I want to process 
these lines line by line. Most of these lines have the same pattern. 
Some of the lines have a different pattern. I want to bundle those 
lines, which have a non-standard pattern, together with the last line 
that had the standard pattern. The number of lines with a non-standard 
pattern is unknown. Are there some algorithms in Phobos that can help 
with this?

Maybe an algorithm combining "chunkBy" and "until" could do it?

Currently I'm using a standard for loop iterating over the lines. I'm 
always looking at the current line and the next line. When the current 
line is the standard pattern and the next line is is not, I do a 
separate loop until I see a standard pattern again, collecting the lines 
with the non-standard pattern in an array.

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list