Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
implement &first, run tests
  • Loading branch information
moritz committed Aug 21, 2011
1 parent eee43c6 commit a638825
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/core/Any.pm
Expand Up @@ -30,6 +30,12 @@ my class Any {
method grep(Mu $test) is rw {
self.map({ $_ if $_ ~~ $test });
}
method first(Mu $test) is rw {
for self.list {
return $_ if $test.ACCEPTS($_);
}
fail 'No values matched';
}

method join($separator = '') {
my $list = (self,).flat.eager;
Expand Down Expand Up @@ -211,6 +217,9 @@ multi map(&code, *@values) { @values.map(&code) }
proto grep(|$) {*}
multi grep(Mu $test, *@values) { @values.grep($test) }

proto first(|$) {*}
multi first(Mu $test, *@values) { @values.first($test) }

proto join(|$) { * }
multi join($sep = '', *@values) { @values.join($sep) }

Expand Down
2 changes: 1 addition & 1 deletion t/spectest.data
Expand Up @@ -503,7 +503,7 @@ S32-io/note.t
S32-list/classify.t
S32-list/create.t
S32-list/end.t
# S32-list/first.t # err: Could not find sub &first
S32-list/first.t
S32-list/grep.t
S32-list/join.t
S32-list/map_function_return_values.t
Expand Down

0 comments on commit a638825

Please sign in to comment.