Skip to content
Browse files

Introducing R:I.AssociativeIterableKeys

An iterator that takes an Associative (or anything else that supports
AT-KEY) and an Iterable, and creates an Iterator of the values of these
keys in the Associative.
  • Loading branch information...
lizmat committed Nov 15, 2018
1 parent 4d8d897 commit 6fe278941a3aee7c0dfc0bf152ce8be71ca99608
Showing with 28 additions and 0 deletions.
  1. +28 −0 src/core/Rakudo/Iterator.pm6
@@ -503,6 +503,34 @@ class Rakudo::Iterator {
method AntiPair(\iterator) { }

# Return an iterator that takes an Associative and an Iterable that
# generates keys, to call the AT-KEY method on the Associative.
my class AssociativeIterableKeys does Iterator {
has $!associative;
has $!iterator;
method !SET-SELF($!associative,$!iterator) { self }
method new(\asso,\iter) { nqp::create(self)!SET-SELF(asso,iter) }

method pull-one() is raw {
nqp::eqaddr((my \key := $!iterator.pull-one),IterationEnd),
method push-all($target --> IterationEnd) {
my \iterator := $!iterator;
my \associative := $!associative;
nqp::eqaddr((my \key := iterator.pull-one),IterationEnd),
method AssociativeIterableKeys(\asso, \iterable) {,iterable.iterator)

# Return an iterator that batches the given source iterator in
# batches of the given size. The third parameter indicates whether
# a partial batch should be returned when the source iterator has

0 comments on commit 6fe2789

Please sign in to comment.
You can’t perform that action at this time.