Skip to content

Commit

Permalink
Make Seq smartmatch Iterables ok
Browse files Browse the repository at this point in the history
Solves R#2233
  • Loading branch information
lizmat committed Aug 29, 2018
1 parent d08a414 commit d3cac14
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/core/Seq.pm6
Expand Up @@ -162,6 +162,28 @@ my class Seq is Cool does Iterable does Sequence {
multi method from-loop(&body, &cond, &afterwards) {
Seq.new(Rakudo::Iterator.CStyleLoop(&body, &cond, &afterwards))
}

multi method ACCEPTS(Seq:D: Iterable:D \iterable --> Bool:D) {
nqp::if(
(my \liter := self.iterator).is-lazy,
False,
nqp::if(
(my \riter := iterable.iterator).is-lazy,
False,
nqp::stmts(
nqp::until(
nqp::eqaddr((my \left := liter.pull-one),IterationEnd),
nqp::if(
nqp::eqaddr((my \right := riter.pull-one),IterationEnd)
|| nqp::not_i(right.ACCEPTS(left)),
(return False)
)
),
nqp::p6bool(nqp::eqaddr(riter.pull-one,IterationEnd))
)
)
)
}
}

sub GATHER(&block) { Seq.new(Rakudo::Iterator.Gather(&block)) }
Expand Down

0 comments on commit d3cac14

Please sign in to comment.