Skip to content

Commit

Permalink
Simplify the iterator method
Browse files Browse the repository at this point in the history
Just build a List, and iterate from that.  No need to build our own
Iterate class.
  • Loading branch information
lizmat committed May 22, 2020
1 parent 187312b commit e9ea048
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions src/core.c/IO/Path/Parts.pm6
Expand Up @@ -29,7 +29,9 @@ class IO::Path::Parts

method of() { Str }

method by-index(int $pos) is implementation-detail {
method iterator() { (:$!volume, :$!dirname, :$!basename).iterator }

method AT-POS(int $pos) {
$pos == 2
?? :$!basename
!! $pos == 1
Expand All @@ -39,18 +41,6 @@ class IO::Path::Parts
!! :$!volume
}

class Iterate does Iterator {
has $!parts;
has int $!i;
method new(\parts) {
nqp::p6bindattrinvres(nqp::create(self),self,'$!parts',parts)
}
method pull-one() { $!i < 3 ?? $!parts.by-index($!i++) !! IterationEnd }
}
method iterator() { Iterate.new(self) }

method AT-POS(int $pos) { self.by-index($pos) }

method AT-KEY(str $key) {
$key eq 'basename'
?? $!basename
Expand Down

0 comments on commit e9ea048

Please sign in to comment.