Or actually maybe just implement an iterator which can give you the next group or next line in the group, instead of processing everything eagerly?