[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] [ruby-talk:4931] Re: Perl 6 rumblings -- RFC 225 (v1) Data: Superpositions (fwd)



On Mon, Sep 18, 2000 at 10:35:49AM +0000, John Carter wrote:
> 
> |>         if (any(@value) < 10) { ... }
> |> 
> |> or:
> |> 
> |>         die unless all(@tests)->($data);
> |> 
> |> ought to be available to all Perl users.
> 
> This can be easily accomplished by the method like
> 
>   module Enumerable
>     def any
>       self.each do |item|
>         return true if yield(item)
>       end
>       return false
>     end
>     def all
>       self.each do |item|
>         return false unless yield(item)
>       end
>       return true
>     end
>   end
> 
>   if tests.all{|x| x < 10} then
>     ...
>   end
> 
> Pretty easy huh?


Replacing 16 lines of Ruby with 2 lines of Perl:

   if (grep {$_ < 10} @value) { ... }
   if (@value == grep {$_ < 10} @value) { ... }


Pretty easy huh?



Abigail

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe