Skip to content

Commit

Permalink
Fix %h.sort(*.key) returning a list of keys only
Browse files Browse the repository at this point in the history
Method sort was missing the transformation back to the original iteration
values.
This naive fix iterates twice. May be faster to replace the push-until-lazy
by a hand coded loop to avoid this.
  • Loading branch information
niner committed Aug 13, 2015
1 parent eb9277c commit 64c3661
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/core/Any-iterable-methods.pm
Expand Up @@ -433,6 +433,11 @@ augment class Any {
unless iter.push-until-lazy(sort-buffer) =:= IterationEnd {
fail X::Cannot::Infinite.new(:action<sort>);
}
my $iteration-buffer;
if $transform {
$iteration-buffer := IterationBuffer.new;
as-iterable(self).iterator.push-until-lazy($iteration-buffer)
}

# Instead of sorting elements directly, we sort a Parcel of
# indices from 0..^$list.elems, then use that Parcel as
Expand All @@ -458,7 +463,9 @@ augment class Any {
}));

my \indices-list = nqp::p6bindattrinvres(List.CREATE, List, '$!reified', indices);
indices-list.map(-> int $i { nqp::atpos(sort-buffer, $i) })
$transform
?? indices-list.map(-> int $i { nqp::atpos($iteration-buffer, $i) })
!! indices-list.map(-> int $i { nqp::atpos(sort-buffer, $i) })
}

proto method reduce(|) { * }
Expand Down

0 comments on commit 64c3661

Please sign in to comment.