> -----Original Message-----
> From: list-bounce / example.com 
> [mailto:list-bounce / example.com] On Behalf Of Jim Weirich
> Sent: Thursday, May 18, 2006 8:59 AM
> To: ruby-talk ML
> Subject: Re: Partial functions?
> 
> 
> Berger, Daniel wrote:
> > Hi all,
> > 
> > I'm trying to understand a new feature of Python 2.5 (PEP 
> 309) called 
> > "partial functions".  Here's the Python example I pulled 
> from Vincent 
> > Foley's blog:
> 
> [... curry example elided ...]
> 
> > I understand what it's doing, I just don't understand what 
> purpose of 
> > partial functions would be.  Can someone provide a use case for me?
> 
> Suppose you have a collection of integers, say a = [1,2,3].  And you 
> wanted to create a new array consisting of all the integers in a, but 
> multiplied by 3.  We have an array method (collect) that constructs a 
> new array by calling a function of one argument on each 
> element of the 
> array.  Now we just need to create a function of one argument 
> to pass to 
> collect:
> 
>   # Convert a 2 arg operator (*)
>   # into a 1 arg function (ie. a lambda).
>   multiply_by_3 = lambda { |n| n * 3 }
> 
>   a = [1,2,3]
>   a_times_3 = a.collect(&multiply_by_3)
> 
> > Also, can/should we do this in Ruby?
> 
> We do it all the time.  We just don't generally bother to 
> give the newly 
> created function a name:
> 
>    a_times_3 = a.collect { |n| n * 3 }
> 
> -- Jim Weirich

Ah, ok.  Is there any kind of speed advantage to this approach?  Or is
it more of a design/DRY technique?

Dan


This communication is the property of Qwest and may contain confidential or
privileged information. Unauthorized use of this communication is strictly 
prohibited and may be unlawful.  If you have received this communication 
in error, please immediately notify the sender by reply e-mail and destroy 
all copies of the communication and any attachments.