Permalink
Browse files

implement &first, run tests

  • Loading branch information...
1 parent eee43c6 commit a638825162f52d08698a33c8663d58632e72d29b @moritz moritz committed Aug 21, 2011
Showing with 10 additions and 1 deletion.
  1. +9 −0 src/core/Any.pm
  2. +1 −1 t/spectest.data
View
@@ -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;
@@ -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) }
View
@@ -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

0 comments on commit a638825

Please sign in to comment.