[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Choice of the word

Gary Wright

7/9/2007 6:53:00 PM


On Jul 4, 2007, at 10:26 AM, Gareth Adams wrote:

> Wayne E. Seguin <wayneeseguin <at> gmail.com> writes:
>
>> The word Inject essentially means to introduce something into a
>> system and yet the inject method iterates over a series elements
>> carrying forward some sort of result at each next step.
>>
>> Hence would it not make more sense to name it " accumulate" which
>> seems to me more explicit and intuitive?
>
> The best I could ever come up with is that the function is
> `injected` between
> the elements of the object

Yes. For me, this rationale becomes clear when you see that

[1,2,3,4].inject { |a,i| a + i }

is the same as

(1 + 2 + 3 + 4)

The binary operator 'plus' has been injected between all the elements
of the collection.


Gary Wright