From 6977973dec1920622a5a673577e243c1bbd23a1c Mon Sep 17 00:00:00 2001 From: Elizabeth Mattijsen Date: Sat, 8 Sep 2018 10:24:56 +0200 Subject: [PATCH] Simplify the Map.kv iterator Using the now existing roles/classes/iterators --- src/core/Map.pm6 | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/src/core/Map.pm6 b/src/core/Map.pm6 index 8e3edd376ce..5e76301ea4f 100644 --- a/src/core/Map.pm6 +++ b/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,