LibreCat / Catmandu

Catmandu - a data processing toolkit
https://librecat.org
175 stars 31 forks source link

Catmandu::Importer->first shouldn't progress (?) #353

Closed nicolasfranck closed 5 years ago

nicolasfranck commented 6 years ago

Whatever the importer you're using, each time you use

$importer->first();

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.

nicolasfranck commented 6 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 ..

nics commented 5 years ago

fixed by pr #354