Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Expose MapIterator role to the world
We can use it in other places in the core
  • Loading branch information
lizmat committed Oct 4, 2015
1 parent d0885e5 commit b6247a8
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/core/Map.pm
@@ -1,5 +1,22 @@
my class X::Hash::Store::OddNumber { ... }

my role MapIterator does Iterator { # needs to be my for some reason
has $!hash-storage;
has $!hash-iter;

method BUILD(\hash) {
$!hash-storage := nqp::getattr(hash, Map, '$!storage');
$!hash-storage := nqp::hash() unless $!hash-storage.DEFINITE;
$!hash-iter := nqp::iterator($!hash-storage);
self
}
method new(\hash) { nqp::create(self).BUILD(hash) }
method count-only() {
$!hash-iter := Mu;
nqp::p6box_i(nqp::elems($!hash-storage))
}
}

my class Map does Iterable does Associative { # declared in BOOTSTRAP
# my class Map is Iterable is Cool {
# has Mu $!storage;
Expand Down Expand Up @@ -59,23 +76,6 @@ my class Map does Iterable does Associative { # declared in BOOTSTRAP
method iterator(Map:) { self.pairs.iterator }
method list(Map:) { self.pairs.cache }

my role MapIterator does Iterator { # needs to be my for some reason
has $!hash-storage;
has $!hash-iter;

method BUILD(\hash) {
$!hash-storage := nqp::getattr(hash, Map, '$!storage');
$!hash-storage := nqp::hash() unless $!hash-storage.DEFINITE;
$!hash-iter := nqp::iterator($!hash-storage);
self
}
method new(\hash) { nqp::create(self).BUILD(hash) }
method count-only() {
$!hash-iter := Mu;
nqp::p6box_i(nqp::elems($!hash-storage))
}
}

multi method pairs(Map:D:) {
Seq.new(class :: does MapIterator {
method pull-one() {
Expand Down

0 comments on commit b6247a8

Please sign in to comment.