Skip to content
Permalink
Browse files

Simplify the Map.kv iterator

Using the now existing roles/classes/iterators
  • Loading branch information...
lizmat committed Sep 8, 2018
1 parent 3b61d4f commit 6977973dec1920622a5a673577e243c1bbd23a1c
Showing with 4 additions and 19 deletions.
  1. +4 −19 src/core/Map.pm6
@@ -211,39 +211,24 @@ my class Map does Iterable does Associative { # declared in BOOTSTRAP
multi method keys(Map:D:) { Seq.new(Rakudo::Iterator.Mappy-keys(self)) }
multi method values(Map:D:) { Seq.new(Rakudo::Iterator.Mappy-values(self)) }

my class KV does Rakudo::Iterator::Mappy {
has int $!on-value;

my class KV does Rakudo::Iterator::Mappy-kv-from-pairs {
method pull-one() is raw {
nqp::if(
$!on-value,
$!on,
nqp::stmts(
($!on-value = 0),
($!on= 0),
nqp::iterval($!iter)
),
nqp::if(
$!iter,
nqp::stmts(
($!on-value = 1),
($!on= 1),
nqp::iterkey_s(nqp::shift($!iter))
),
IterationEnd
)
)
}
method skip-one() {
nqp::if(
$!on-value,
nqp::not_i($!on-value = 0), # skipped a value
nqp::if(
$!iter, # if false, we didn't skip
nqp::stmts( # skipped a key
nqp::shift($!iter),
($!on-value = 1)
)
)
)
}
method push-all($target --> IterationEnd) {
nqp::while( # doesn't sink
$!iter,

0 comments on commit 6977973

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