Martin DeMello wrote:
> On Nov 12, 2007 11:10 AM,  <furtive.clown / gmail.com> wrote:
>>
>> This is the first I've heard of Object#tap.  It seems backward because
>> you almost always want the result of the block, not the object back
>> again.
> 
> #tap is the opposite use case - you want to "tap" the object stream,
> observing without affecting. It's very handy for debugging, where you
> can tap into a chain of method calls, print something out and continue
> on your way, e.g.
> 
> foo.map(&:bar).tap {|a| p a}.inject...
> 
> martin

That's a great example of a use-case for #tap. (I think I remember that 
from the original discussion of the feature.) But the K-combinator style 
side-effect is valid too. Just look at all the uses of #returning in 
Rails.

-- 
Posted via http://www.ruby-forum.com/.