Algorithm-Combinatorics
view release on metacpan or search on metacpan
Combinatorics.pm view on Meta::CPAN
# This is a bit dirty by now, the objective is to be able to
# pass an initial sequence to the iterator and avoid a test
# in each iteration saying whether the sequence was already
# returned or not, since that might potentially be done a lot
# of times.
#
# The solution is to return an iterator that has a first sequence
# associated. The first time you call it that sequence is returned
# and the iterator rebless itself to become just a wrapped coderef.
#
# Note that the public contract is that responds to next(), no
# iterator class name is documented.
package Algorithm::Combinatorics::Iterator;
sub new {
my ($class, $coderef, $first_seq) = @_;
if (defined $first_seq) {
return bless [$coderef, $first_seq], $class;
} else {
return bless $coderef, 'Algorithm::Combinatorics::JustCoderef';
}
( run in 0.433 second using v1.01-cache-2.11-cpan-64827b87656 )