Skip to content

Commit

Permalink
Quick lazy implementations of Any.keys and Any.values, plus matching …
Browse files Browse the repository at this point in the history
…protos.
  • Loading branch information
colomon committed Feb 25, 2010
1 parent 9a1d71b commit 72a95fc
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/core/Any-list.pm
Expand Up @@ -171,6 +171,20 @@ augment class Any {
take $value;
}
}

multi method keys() {
my $i = 0;
gather for $.list -> $value {
my $key = $i++;
take $key;
}
}

multi method values() {
gather for $.list -> $value {
take $value;
}
}
}

our proto sub join (Str $separator = '', *@values) { @values.join($separator); }
Expand All @@ -185,5 +199,7 @@ our proto sub uniq(@values) { @values.uniq; }
our proto sub pick ($num, :$replace, *@values) { @values.pick($num, :$replace); }
our proto sub map(&mapper, @values) { @values.map(&mapper); }
our proto sub kv(@array) { @array.kv; }
our proto sub keys(@array) { @array.keys; }
our proto sub values(@array) { @array.values; }

# vim: ft=perl6

0 comments on commit 72a95fc

Please sign in to comment.