On Tuesday, January 21, 2003, at 02:04  AM, Graham Barr wrote:
If the function form of map/grep were to be removed, which has been suggested,
and the <~ form maps to methods. How would you go about defining a utility
module similar to List::Util that uses the same syntax as map/grep but
without making the subs methods on the global ARRAY package ?
If you want the method to be available everywhere, you probably _should_ make it a method of the global Array class. More typically, perhaps, you'd only be using your new method to operate on certain arrays that you use, in which case you would make a new class for those particular arrays, so your new method would work only on the specific arrays you intended it to:

class MyArray is Array {
method foo_grep (Code $test) returns MyArray {
...
}
}

my @a is MyArray = (1..10);
my @b = @a.foo_grep {...};
my @c = foo_grep {...} <~ @a; # identical

I don't see any problem (other than maybe a philosophical objection) with making them methods of Array, though, if they're valuable enough. That certainly would seem the common Perl thing to do.

MikeL



Reply via email to