$sub->($_) for CORE::values %$hash;
}
+sub each_n_values {
+ my ($hash, $n, $sub) = @_;
+ my @keys = CORE::keys %$hash;
+ my $it = List::MoreUtils::natatime($n, @keys);
+
+ while (my @vals = $it->()) {
+ $sub->(@$hash{ @vals });
+ }
+
+ return;
+}
+
# End Indexed
}
}
+{
+ my %hash = (a => 1, b => 2, c => 3, d => 4);
+
+ my $href = { %hash };
+
+ {
+ my @vals;
+ %hash->each_n_values(2, sub { push @vals, [@_] });
+ my %seen;
+ is(@vals, 2);
+ for my $pair (@vals) { $seen{$_}++ for @$pair }
+ is_deeply(\%seen, { 1,1,2,1,3,1,4,1 });
+ }
+
+ {
+ my @vals;
+ $href->each_n_values(2, sub { push @vals, [@_] });
+ my %seen;
+ is(@vals, 2);
+ for my $pair (@vals) { $seen{$_}++ for @$pair }
+ is_deeply(\%seen, { 1,1,2,1,3,1,4,1 });
+ }
+}
+
done_testing;