Patrick R. Michaud via RT wrote: > + 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))); > + } > + } > + } > > Especially in class C<Any>, we should _not_ be placing any constraints > on the invocant -- the above use of @values would constrain this to be > an array. Change it to be $values, or (even better) just use 'self'. > > Instead of doing a test for @indices in each iteration I'd think we > could do the test once at the beginning and decide which path we're > likely to take from there.
I hope I fixed both of your concerns with this commit: commit 051ad5115268e5415bebb1988cbf0b1be626156b Author: Moritz Lenz <mor...@faui2k3.org> Date: Sun Mar 8 20:10:24 2009 +0100 remove implicit type constraint in .pairs Also refactored to make a bit faster when no indices are given, pmichaud++ diff --git a/src/setting/Any-list.pm b/src/setting/Any-list.pm index 763a5ab..be5f723 100644 --- a/src/setting/Any-list.pm +++ b/src/setting/Any-list.pm @@ -33,11 +33,16 @@ class Any is also { }; - multi method pairs(@values: *...@indices) { + multi method pairs(*...@indices) { gather { - for (@values.keys Z @values) -> $key, $val is rw { - take ($key => $val) - unless (@indices && ($key !~~ any(@indices))); + if @indices { + for (self.list.keys Z self.list) -> $key, $val is rw { + take ($key => $val) if $key ~~ any(@indices); + } + } else { + for (self.list.keys Z self.list) -> $key, $val is rw { + take ($key => $val) + } } } } With this commit this also works: $ ./perl6 -e 'say 3.pairs' 0 3 I'll push it to github once the spectest is gone through, and indicates that all is well. Cheers, Moritz