Skip to content

Commit

Permalink
Turn Array.exists into List.exists, write it a bit cleaner.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Jun 24, 2010
1 parent 18682c8 commit bf5bbd4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
7 changes: 0 additions & 7 deletions src/core/Array.pm
@@ -1,11 +1,4 @@
augment class Array {
our Bool multi method exists(*@indices) {
if !@indices.elems || (any(@indices) < 0 || any(@indices) > self.end) {
return False;
}
[?&] map { self[$^a] !~~ Proxy }, @indices;
}

method at_pos($pos) {
Q:PIR {
.local pmc self, items
Expand Down
9 changes: 9 additions & 0 deletions src/core/List.pm
Expand Up @@ -13,6 +13,15 @@ augment class List does Positional {

method Str() { self.join(' ') }

multi method exists(*@indices) {
return False unless @indices;
while @indices && @indices.shift -> $key {
return False if $key < 0
|| !pir::exists__IQi(self!fill($key+1), $key);
}
True;
}

multi method fmt($format = '%s', $separator = ' ') {
self.map({ .fmt($format) }).join($separator);
}
Expand Down

0 comments on commit bf5bbd4

Please sign in to comment.