Skip to content

Instantly share code, notes, and snippets.

@colomon
Created June 14, 2010 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colomon/438028 to your computer and use it in GitHub Desktop.
Save colomon/438028 to your computer and use it in GitHub Desktop.
class SolIter is Iterator {
has $!value;
has $!max;
has $!excludes_max;
has $!last_flag;
has $!next-iter;
multi method new(Range $r) {
self.bless(*, :value($r.excludes_min ?? $r.min.succ !! $r.min),
:max($r.max),
:excludes_max($r.excludes_max),
:last_flag(False)
);
}
multi method new($value, $max, $excludes_max) {
self.bless(*, :value($value),
:max($max),
:excludes_max($excludes_max),
:last_flag(False)
);
}
# method get() {
# my $current = $!value;
# if $!last_flag {
# return EMPTY;
# }
# unless $!max ~~ ::Whatever {
# if SolIterCmp($current, $!max) == 1
# || $!excludes_max && SolIterCmp($current, $!max) != -1 {
# return EMPTY;
# }
# }
# $!value .= succ;
# if ($!value cmp $current) == 0 {
# $!last_flag = True;
# }
# $current;
# }
method reify() {
unless $!next-iter.defined {
say "reify { $!value }";
if $!value ~~ EMPTY
|| $!value cmp $!max == 1
|| $!excludes_max && $!value cmp $!max != -1 {
say 'b';
$!next-iter = SolIter.new(EMPTY, $!max, $!excludes_max);
} else {
say 'a';
$!next-iter = SolIter.new($!value.succ, $!max, $!excludes_max);
say 'yeh';
}
}
say 'willie';
$!value, $!next-iter;
}
}
my $a = SolIter.new(10, 15, Bool::False);
my ($value, $next) = $a.reify;
say $value;
# ($value, $next) = $next.reify;
# say $value;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment