Skip to content

Commit

Permalink
Tmplement Supply.split(Str)
Browse files Browse the repository at this point in the history
As promised before.  First candidate of Supply.split, with more to
come.
  • Loading branch information
lizmat committed Jan 12, 2020
1 parent 9864288 commit cac64ca
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/core.c/Supply.pm6
Expand Up @@ -671,6 +671,29 @@ my class Supply does Awaitable {
}
}

# split the supply on the given string
multi method split(Supply:D: Str(Cool) $the-needle) {
supply {
my str $str;
my str $needle = $the-needle;

whenever self -> str $val {
my $matches := nqp::split($needle,nqp::concat($str,$val));
$str = nqp::pop($matches); # keep last for next batch

my $iterator := nqp::iterator($matches);
nqp::while(
$iterator,
emit nqp::p6box_s(nqp::shift($iterator))
);

LAST {
emit nqp::p6box_s($str);
}
}
}
}

##
## Coercions
##
Expand Down

0 comments on commit cac64ca

Please sign in to comment.