Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
The collect method converts the parsed data into a list of items, and if a pagination indicator is found, it makes another api request, parses the data and adds it to the accumulator, ..., until no pagination indicator is found, then returns the accumulated items.my $data = $api->request(...); for my $item ($api->collect($data)) { process($item); for my $widget ($api->gather($item->{sets}{widgets})) { process($widget); } }
This is not a good design, since the memory usage can rise unacceptably high, so I'd like to change the implementation details of collect to make use of an iterator or tied array and avoid accumulating, but I would also like to keep the current user interface of simply iteratoring over the results with a for loop. Is this possible?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using lazy list with a for loop (updated)
by haukex (Archbishop) on Jan 02, 2023 at 23:18 UTC | |
by Anonymous Monk on Jan 03, 2023 at 00:29 UTC | |
|
Re: Using lazy list with a for loop
by LanX (Saint) on Jan 02, 2023 at 23:44 UTC | |
by Anonymous Monk on Jan 02, 2023 at 23:58 UTC | |
by LanX (Saint) on Jan 03, 2023 at 00:15 UTC | |
by Anonymous Monk on Jan 03, 2023 at 00:26 UTC | |
by LanX (Saint) on Jan 03, 2023 at 00:33 UTC | |
| |
|
Re: Using lazy list with a for loop
by Anonymous Monk on Jan 02, 2023 at 22:38 UTC | |
by erzuuli (Cannon) on Jan 03, 2023 at 03:54 UTC |