Closed nicolasfranck closed 5 years ago
Can an importer actually support methods like "first" and "rest"? An importer is progressive in nature, and there is no way to reset the filehandle.
Consider these "records": [ 0 .. 9 ]
#get record "0" (as expected)
$importer->first();
#gets records "2" to "9"
$importer->rest->to_array()
Record "1" disappears, right? That last thing happens because method "first" already chopped off the first record, and "rest" thinks it has to skip a record (nr. "1").
Of course this will work for iterators like bags, ArrayIterator ..
fixed by pr #354
Whatever the importer you're using, each time you use
it progresses, and returns the next record.
Is this intended?
Shouldn't that always be the same record?
A quick fix would be to make "first" into a Moo attribute that is filled with the first record in a lazy manner. Probably not so easy, especially when someone has already called the generator once or more.
Another option would be to rename it to "next" which covers the current meaning and deprecate the old name.