Skip to content

Commit

Permalink
Introduce Rakudo::Iterator.Truthy
Browse files Browse the repository at this point in the history
Not used yet, but will be used for .split(:skip-empty) functionality
and possibly other situations
  • Loading branch information
lizmat committed Jun 5, 2020
1 parent d984e7c commit bf01f84
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/core.c/Rakudo/Iterator.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -4099,6 +4099,26 @@ class Rakudo::Iterator {
}
method Toggle(\iter, \conds, $on) { Toggle.new(iter, conds, $on) }

# Return an iterator for the Truthy values of an iterator
my class Truthy does Iterator {
has Mu $!iterator;
method new(\iterator) {
nqp::p6bindattrinvres(
nqp::create(self),self,'$!iterator',iterator)
}
method pull-one() is raw {
nqp::until(
nqp::eqaddr((my $pulled := $!iterator.pull-one),IterationEnd),
nqp::if(
$pulled,
return $pulled
)
);
IterationEnd
}
}
method Truthy(\iterator) { Truthy.new(iterator) }

# Return an iterator that only will return the two given values.
my class TwoValues does Iterator {
has Mu $!val1;
Expand Down

0 comments on commit bf01f84

Please sign in to comment.