Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

implement &first, run tests

  • Loading branch information...
commit a638825162f52d08698a33c8663d58632e72d29b 1 parent eee43c6
@moritz moritz authored
Showing with 10 additions and 1 deletion.
  1. +9 −0 src/core/Any.pm
  2. +1 −1  t/spectest.data
View
9 src/core/Any.pm
@@ -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
2  t/spectest.data
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.