From edcd4ace5854e416a2b2bc678ec68d5887c9c781 Mon Sep 17 00:00:00 2001
From: Cory Spencer <cspencer@sprocket-2.local>
Date: Sat, 7 Mar 2009 20:47:11 -0800
Subject: [PATCH] Squashed commit of the following:

commit c628274f1c84b24831cc98e9fe0f77984e4c056b
Author: Cory Spencer <cspencer@sprocket-2.local>
Date:   Sat Mar 7 20:43:33 2009 -0800

    Replaced the PIR Any.pairs method with a Perl 6 version.
---
 src/builtins/any-list.pir |   31 -------------------------------
 src/setting/Any-list.pm   |   13 +++++++++++++
 2 files changed, 13 insertions(+), 31 deletions(-)

diff --git a/src/builtins/any-list.pir b/src/builtins/any-list.pir
index d43a414..46f9444 100644
--- a/src/builtins/any-list.pir
+++ b/src/builtins/any-list.pir
@@ -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
diff --git a/src/setting/Any-list.pm b/src/setting/Any-list.pm
index 9492c54..1a6fd29 100644
--- a/src/setting/Any-list.pm
+++ b/src/setting/Any-list.pm
@@ -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) {
@@ -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
-- 
1.6.1.3

