in reply to Efficient but elegant Cross-Product iterator ?
That's exactly what Algorithm::Loops's NestedLoop does.
use Algorithm::Loops qw( NestedLoop ); my $iter = NestedLoop([ map { [ $_->() ] } @subs ]); while ( my @items = $iter->() ) { ... }
Update: LanX points out the above can be simplified if the subs return the same thing each time they are called. They also need to return the values via a reference to an array.
use Algorithm::Loops qw( NestedLoop ); my $iter = NestedLoop(\@subs); while ( my @items = $iter->() ) { ... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Efficient but elegant Cross-Product iterator ?
by LanX (Saint) on Jun 20, 2020 at 21:44 UTC | |
by ikegami (Patriarch) on Jun 20, 2020 at 21:59 UTC | |
by LanX (Saint) on Jun 20, 2020 at 22:00 UTC | |
by ikegami (Patriarch) on Jun 20, 2020 at 22:05 UTC | |
by LanX (Saint) on Jun 20, 2020 at 22:12 UTC |