Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement squish() and .squish(), as per S32/Containers
  • Loading branch information
lizmat committed Jul 3, 2013
1 parent 174bf4f commit f069282
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/core/Any.pm
Expand Up @@ -17,6 +17,7 @@ my class Any {
method classify($test) { {}.classify( $test, self.list ) }
method categorize($test) { {}.categorize( $test, self.list ) }
method uniq() { self.list.uniq }
method squish() { self.list.squish }
method infinite() { Mu }
method flat() { nqp::p6list(nqp::list(self), List, Bool::True) }
method hash() { my % = self }
Expand Down Expand Up @@ -786,6 +787,9 @@ multi categorize( $test, *@items ) { {}.categorize( $test, @items ) }
proto uniq(|) { * }
multi uniq(*@values) { @values.uniq }

proto squish(|) { * }
multi squish(*@values) { @values.squish }

proto sub sort(|) {*}
multi sub sort(*@values) {
@values.at_pos(0).^does(Callable)
Expand Down
9 changes: 9 additions & 0 deletions src/core/List.pm
Expand Up @@ -335,6 +335,15 @@ my class List does Positional {
}
}

my @secret;
method squish() {
my $last = @secret;
gather sink for @.list {
take $_ if $_ !=== $last;
$last = $_;
}
}

multi method gist(List:D:) { join ' ', map { $_.gist }, @(self) }
multi method perl(List:D \SELF:) {
self.gimme(*);
Expand Down
1 change: 1 addition & 0 deletions t/spectest.data
Expand Up @@ -637,6 +637,7 @@ S32-list/reverse.t
S32-list/roll.t
S32-list/sort.t
S32-list/uniq.t
S32-list/squish.t
S32-num/abs.t
S32-num/base.t
S32-num/complex.t
Expand Down

0 comments on commit f069282

Please sign in to comment.