Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make eager actually eager, not just a promise to be eager later on
also both List.eager and Seq.eager return a List now.
This causes a regression in S02-types/lazy-lists.t, but makes
"try { eager map { die }, 1 }" work.
  • Loading branch information
moritz committed Aug 25, 2015
1 parent d747af1 commit 48791be
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 63 deletions.
63 changes: 0 additions & 63 deletions src/core/Iterable.pm
Expand Up @@ -78,69 +78,6 @@ my role Iterable {
}.new(self))
}

method eager() {
Seq.new(class :: does Iterator {
has $!iterator;
has $!cache;

method new(\iterator) {
my \iter = self.CREATE;
nqp::bindattr(iter, self, '$!iterator', iterator);
iter
}

method pull-one() is rw {
self!fill-cache() unless $!cache.DEFINITE;
nqp::elems($!cache)
?? nqp::shift($!cache)
!! IterationEnd
}

method push-exactly($target, int $n) {
self!fill-cache() unless $!cache.DEFINITE;
my $cache := $!cache;
my int $todo = $n < nqp::elems($cache)
?? $n
!! nqp::elems($cache);
my int $i = 0;
while $i < $n {
$target.push(nqp::shift($cache));
$i = $i + 1
}
nqp::elems($cache)
?? $todo
!! IterationEnd
}

method push-at-least($target, int $n) {
self!all($target)
}

method push-until-lazy($target) {
self!all($target)
}

method push-all($target) {
self!all($target)
}

method !fill-cache() {
$!cache := IterationBuffer.CREATE;
$!iterator.push-all($!cache);
}

method !all($target) {
# Normally if we end up here, we didn't pull things into the
# cache. But if we did, delegate to the default version of
# push-all from the role to make sure we eat out the cache,
# not from the now-depleted iterator.
$!cache.DEFINITE
?? self.Iterator::push-all($target)
!! $!iterator.push-all($target)
}
}.new(self.iterator))
}

method hyper(Int(Cool) :$batch = 64, Int(Cool) :$degree = 4) {
self!go-hyper(HyperConfiguration.new(:!race, :$batch, :$degree))
}
Expand Down
4 changes: 4 additions & 0 deletions src/core/List.pm
Expand Up @@ -504,6 +504,10 @@ my class List does Iterable does Positional { # declared in BOOTSTRAP
# batch up the work too).
Array.from-iterator(self.iterator)
}
method eager {
$!todo.reify-all() if $!todo.DEFINITE;
self;
}

method Capture() {
$!todo.reify-all() if $!todo.DEFINITE;
Expand Down
4 changes: 4 additions & 0 deletions src/core/Seq.pm
Expand Up @@ -51,6 +51,10 @@ my class Seq is Cool does Iterable does PositionalBindFailover {
iter.is-lazy
}

method eager {
List.from-iterator(self.iterator).eager;
}

method List() {
List.from-iterator(self.iterator)
}
Expand Down

0 comments on commit 48791be

Please sign in to comment.