Skip to content

Commit

Permalink
Give Junction an iterator method
Browse files Browse the repository at this point in the history
While methods in general autothread, some opt out of that - especially
those called by internals and that are expected to follow protocols. It
would seem `iterator` is a fair fit for that category, so implement it
as an iterator that produces 1 value when iterated: the Junction itself.
The current bad behavior in #3198
is eliminated by this change; it now outputs `Junction` instead.
  • Loading branch information
jnthn committed Feb 5, 2020
1 parent ca78390 commit bceaeb1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/core.c/Junction.pm6
Expand Up @@ -262,6 +262,14 @@ my class Junction { # declared in BOOTSTRAP
)
}

multi method iterator(Junction:D:) {
# If we're asked for an iterator, we should really give one rather than
# auto-thread over the `iterator` method. Otherwise we get decidedly
# confusing outcomes from things that do `.iterator` and then expect it
# to follow the iterator API.
list(self).iterator
}

multi method gist(Junction:D:) {
my int $elems = nqp::elems($!storage);
my int $i = -1;
Expand Down

0 comments on commit bceaeb1

Please sign in to comment.