Skip to content

Commit

Permalink
Replaced the PIR Any.pairs method with a Perl 6 version.
Browse files Browse the repository at this point in the history
Signed-off-by: Moritz Lenz <moritz@faui2k3.org>
  • Loading branch information
Cory Spencer authored and moritz committed Mar 8, 2009
1 parent 137dcfa commit 8b2a4ad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 31 deletions.
31 changes: 0 additions & 31 deletions src/builtins/any-list.pir
Expand Up @@ -259,37 +259,6 @@ Return a List with the keys of the invocant.
.return (result)
.end


=item pairs()

=cut

.namespace []
.sub 'pairs' :multi()
.param pmc values :slurpy
values.'!flatten'()
.tailcall values.'pairs'()
.end

.namespace ['Any']
.sub 'pairs' :method
.local pmc result, it
result = new 'List'
it = self.'iterator'()
.local int i
i = 0
loop:
unless it goto done
$P0 = shift it
$P1 = 'infix:=>'(i, $P0)
push result, $P1
inc i
goto loop
done:
.return (result)
.end


=item pick($num, :$repl)

=cut
Expand Down
13 changes: 13 additions & 0 deletions src/setting/Any-list.pm
Expand Up @@ -21,6 +21,15 @@ class Any is also {
our List of Capture multi method map($value: Code *&expr) {
($value,).map: &expr
}

our List multi method pairs(@values: *@indices) {
gather {
for (@values.keys Z @values) -> $key, $val is rw {
take ($key => $val)
unless (@indices && ($key !~~ any(@indices)));
}
}
}
}

our List multi grep(Code $test, *@values) {
Expand All @@ -31,4 +40,8 @@ our List of Capture multi map(Code $expr, *@values) {
@values.map($expr)
}

our List multi pairs(@values, *@indices) {
@values.pairs(@indices)
}

# vim: ft=perl6

0 comments on commit 8b2a4ad

Please sign in to comment.