Skip to content

Commit

Permalink
Revert "Deprecate grep-index in favour of grep :index"
Browse files Browse the repository at this point in the history
<TimToady>  :k, :kv, :p should follow the same policy as subscripting does

My patch only partially addresses this, and it seems inappropriate to put this
in just before the release tomorrow.
  • Loading branch information
lizmat committed Apr 22, 2015
1 parent f1d5d0f commit 049fe61
Showing 1 changed file with 26 additions and 30 deletions.
56 changes: 26 additions & 30 deletions src/core/Any.pm
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ my class Any { # declared in BOOTSTRAP
}

proto method grep(|) { * }
multi method grep(Bool:D \t, |c) is rw {

This comment has been minimized.

Copy link
@vendethiel

vendethiel Apr 22, 2015

Contributor

this didn't seem necessary (the |c) as it's a method

multi method grep(Bool:D $t) is rw {
fail X::Match::Bool.new( type => '.grep' );
}
multi method grep(Regex:D $test) is rw {
Expand All @@ -236,42 +236,36 @@ my class Any { # declared in BOOTSTRAP
multi method grep(Mu $test) is rw {
self.map({ next unless $_ ~~ $test; $_ });
}
multi method grep(Regex:D $test, :$index!) {
return self.grep($test) if !$index;

my int $i = -1;
proto method grep-index(|) { * }
multi method grep-index(Bool:D $t) is rw {
fail X::Match::Bool.new( type => '.grep-index' );
}
multi method grep-index(Regex:D $test) {
my int $index = -1;
self.map: {
$i = $i + 1;
$index = $index+1;
next unless .match($test);
nqp::box_i($i,Int);
nqp::box_i($index,Int);
};
}
multi method grep(Callable:D $test, :$index!) {
return self.grep($test) if !$index;

my int $i = -1;
multi method grep-index(Callable:D $test) {
my int $index = -1;
self.map: {
$i = $i + 1;
$index = $index + 1;
next unless $test($_);
nqp::box_i($i,Int);
nqp::box_i($index,Int);
};
}
multi method grep(Mu $test, :$index!) {
return self.grep($test) if !$index;

my int $i = -1;
multi method grep-index(Mu $test) {
my int $index = -1;
self.map: {
$i = $i + 1;
$index = $index + 1;
next unless $_ ~~ $test;
nqp::box_i($i,Int);
nqp::box_i($index,Int);
};
}

method grep-index(Mu $test) is rw {
DEPRECATED('grep with :index',|<2015.04 2015.09>);
self.grep($test, :index);
}

proto method first(|) { * }
multi method first(Bool:D $t) is rw {
fail X::Match::Bool.new( type => '.first' );
Expand Down Expand Up @@ -703,13 +697,15 @@ multi sub map(Whatever, \a) { a }
multi sub map(&code, Whatever) { (1..Inf).map(&code) }

proto sub grep(|) {*}
multi sub grep(Mu $test, @values, |c) { @values.grep($test,|c) }
multi sub grep(Mu $test, *@values, |c) { @values.grep($test,|c) }
multi sub grep(Bool:D $t, *@v, |c) { fail X::Match::Bool.new( type => 'grep' ) }

sub grep-index(Mu $test, *@values) {
DEPRECATED("grep with :index",|<2015.04 2015.09>);
@values.grep($test, :index)
multi sub grep(Mu $test, @values) { @values.grep($test) }
multi sub grep(Mu $test, *@values) { @values.grep($test) }
multi sub grep(Bool:D $t, *@v) { fail X::Match::Bool.new( type => 'grep' ) }

proto sub grep-index(|) {*}
multi sub grep-index(Mu $test, @values) { @values.grep-index($test) }
multi sub grep-index(Mu $test, *@values) { @values.grep-index($test) }
multi sub grep-index(Bool:D $t, *@v) {
fail X::Match::Bool.new(type => 'grep-index');
}

proto sub first(|) {*}
Expand Down

0 comments on commit 049fe61

Please sign in to comment.