Skip to content

Commit

Permalink
Give EnumMap (and thus Hash) .iterator, .keys, .values and .kv, all d…
Browse files Browse the repository at this point in the history
…one in the core setting.
  • Loading branch information
jnthn committed Feb 7, 2010
1 parent b652882 commit 16fd613
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/core/EnumMap.pm
Expand Up @@ -20,6 +20,32 @@ role EnumMap {
}
}


method iterator() {
# We just work off the low-level Parrot iterator.
my $iter = pir::iter__PP($!storage);
gather {
while pir::istrue__IP($iter) {
my $iter_item = pir::shift__PP($iter);
take Pair.new(key => $iter_item.key, value => $iter_item.value);
}
}
}

method keys() {
self.iterator.map({ $^pair.key })
}

method kv() {
gather {
for self.iterator -> $pair {
take $pair.key;
take $pair.value;
}
}
}

method values() {
self.iterator.map({ $^pair.value })
}
}

0 comments on commit 16fd613

Please sign in to comment.