From 0977b1ec693f8bff64b3af92e8c4432d22c394ff Mon Sep 17 00:00:00 2001 From: Solomon Foster Date: Thu, 24 Dec 2009 10:33:20 -0500 Subject: [PATCH] Lightly tested ng versions of the Rakudo Any.first and Any.grep methods. --- src/core/Any-list.pm | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/core/Any-list.pm b/src/core/Any-list.pm index 6620b82c9f6..b97c9c6a998 100644 --- a/src/core/Any-list.pm +++ b/src/core/Any-list.pm @@ -19,6 +19,24 @@ augment class Any { } } + multi method first($test) { + for @.list { + if $_ ~~ $test { + return $_; + } + } + + fail('No values matched'); + } + + our List multi method grep($test) { + gather { + for @.list { + take $_ if $_ ~~ $test; + } + } + } + multi method reverse() { my @result; for @.list {