Skip to content

Commit

Permalink
Add Array.delete.
Browse files Browse the repository at this point in the history
  • Loading branch information
colomon committed Jan 3, 2012
1 parent a658ef8 commit 5fd7180
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/CORE.setting
Expand Up @@ -15,6 +15,7 @@ my class Array { ... }
my class FatRat { ... }
my class Junction { ... }
my class Enum { ... }
my class Range { ... }
# }}}
# Important inlinable definitions {{{
sub infix:<+>($l,$r) is Niecza::builtin('plus',2,2) { $l + $r }
Expand Down Expand Up @@ -1245,6 +1246,22 @@ my class Array is List {
$self // return $self.typename;
"[" ~ $self.map(*.perl).join(', ') ~ "]" ~ ($self.flattens ?? ".list" !! "");
}
method delete(*@indices) {
my @result;
my @i = @indices.map({
when Range { $_.iterator.list }
when Callable { $_(+self) }
when * < 0 { die "Negative index not allowed, please use WhateverCode" }
$_;
});
for @i -> $i {
@result.push(self[$i]);
self[$i] = Any;
}
self.pop while ?self && !defined self[*-1];
return @result;
}
}
# Not connected to Hash because Stash contains bvalues while Hash
Expand Down

0 comments on commit 5fd7180

Please sign in to comment.