Skip to content

Commit

Permalink
Introducing EmptySeq constant
Browse files Browse the repository at this point in the history
- The Empty Sequence (we only need one of them)
- use EmptySeq in setting where possible

Empty sequences in Any-iterable-methods and Str where too soon in the setting.
Please revert if having an EmptySeq constant is a bad idea.
  • Loading branch information
lizmat committed Jan 7, 2018
1 parent d034cb5 commit b4df753
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/core/IO/CatHandle.pm
Expand Up @@ -115,7 +115,8 @@ my class IO::CatHandle is IO::Handle {
nqp::while(
nqp::defined(self.next-handle),
take $!active-handle.words)}),
Seq.new: Rakudo::Iterator.Empty)
EmptySeq
)
}
multi method words(::?CLASS:D \SELF: $limit, :$close) {
nqp::istype($limit,Whatever) || $limit == Inf
Expand All @@ -140,7 +141,8 @@ my class IO::CatHandle is IO::Handle {
nqp::while(
nqp::defined(self.next-handle),
take $!active-handle.lines)}),
Seq.new: Rakudo::Iterator.Empty)
EmptySeq
)
}
multi method lines(::?CLASS:D \SELF: $limit, :$close) {
nqp::istype($limit,Whatever) || $limit == Inf
Expand Down
2 changes: 1 addition & 1 deletion src/core/IO/Spec/Unix.pm
Expand Up @@ -104,7 +104,7 @@ my class IO::Spec::Unix is IO::Spec {
nqp::until(
nqp::iseq_i($els, $i = nqp::add_i($i, 1)),
take nqp::atpos($parts, $i) || '.')
} !! Seq.new: Rakudo::Iterator.Empty
} !! EmptySeq
}

method splitpath( $path, :$nofile = False ) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/Mixy.pm
Expand Up @@ -43,7 +43,7 @@ my role Mixy does Baggy {
nqp::if(
(my $total := self!total-positive),
self.roll($calculate($total)),
Seq.new(Rakudo::Iterator.Empty)
EmptySeq
)
}
multi method roll(Mixy:D: $count) {
Expand Down
8 changes: 4 additions & 4 deletions src/core/Range.pm
Expand Up @@ -502,7 +502,7 @@ my class Range is Cool does Iterable does Positional {
!! self.list.roll(*)
}
else {
Seq.new(Rakudo::Iterator.Empty)
EmptySeq
}
}
multi method roll(Range:D:) {
Expand Down Expand Up @@ -547,7 +547,7 @@ my class Range is Cool does Iterable does Positional {
!! self.list.roll($todo)
}
else {
Seq.new(Rakudo::Iterator.Empty)
EmptySeq
}
}

Expand All @@ -556,7 +556,7 @@ my class Range is Cool does Iterable does Positional {
multi method pick(Whatever) {
self.elems
?? self.list.pick(*)
!! Seq.new(Rakudo::Iterator.Empty)
!! EmptySeq
}
multi method pick(Int(Cool) $todo) {
if self.elems -> $elems {
Expand Down Expand Up @@ -606,7 +606,7 @@ my class Range is Cool does Iterable does Positional {
!! self.list.pick($todo)
}
else {
Seq.new(Rakudo::Iterator.Empty)
EmptySeq
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/core/Seq.pm
Expand Up @@ -340,4 +340,10 @@ multi sub infix:<eqv>(Seq:D \a, Seq:D \b) {
)
}

# The Empty Sequence
my constant EmptySeq = nqp::p6bindattrinvres(
nqp::create( class EmptySeq is Seq {
method iterator() { nqp::getattr(self,Seq,'$!iter') }
}),Seq,'$!iter',Rakudo::Iterator.Empty);

# vim: ft=perl6 expandtab sw=4

0 comments on commit b4df753

Please sign in to comment.