Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement Supply.uniq( :with, :expires)
And fix Supply.uniq( :expires ) (without :with)
  • Loading branch information
lizmat committed Apr 23, 2014
1 parent f724dd5 commit 261f440
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/core/SupplyOperations.pm
Expand Up @@ -147,15 +147,33 @@ my class SupplyOperations is repr('Uninstantiable') {
my Mu $target;
&as
?? -> \val {
my $now := now;
$target = &!as(val);
if @seen.first({ &!with($target,$_) } ) =:= Nil {
my $index =
@seen.first-index({&!with($target,$_[0])});
if $index.defined {
if @seen[$index][1] < $now { # expired
@seen[$index][1] = $now + $expires;
self!more(val);
}
}
else {
@seen.push($target);
self!more(val);
}
}
!! -> \val {
if @seen.first({ &!with(val,$_) } ) =:= Nil {
@seen.push(val);
my $now := now;
my $index =
@seen.first-index({&!with(val,$_[0])});
if $index.defined {
if @seen[$index][1] < $now { # expired
@seen[$index][1] = $now + $expires;
self!more(val);
}
}
else {
@seen.push($target);
self!more(val);
}
};
Expand All @@ -169,7 +187,7 @@ my class SupplyOperations is repr('Uninstantiable') {
$target = nqp::unbox_s(&!as(val).WHICH);
if nqp::existskey($seen, $target) {
self!more(val) # expired
if nqp::atkey($seen,$target) > $now;
if nqp::atkey($seen,$target) < $now;
}
else {
self!more(val);
Expand All @@ -181,7 +199,7 @@ my class SupplyOperations is repr('Uninstantiable') {
$target = nqp::unbox_s(val.WHICH);
if nqp::existskey($seen, $target) {
self!more(val) # expired
if nqp::atkey($seen,$target) > $now;
if nqp::atkey($seen,$target) < $now;
}
else {
self!more(val);
Expand Down

0 comments on commit 261f440

Please sign in to comment.