What is the difference between inject and reduce methods

Rubysters,

I often use inject method (where and when I want to. Lol!). I would like
to
know the difference between inject and reduce methods. I find them
similar.

Ref: http://www.ruby-doc.org/core/classes/Enumerable.html#M001495


Edmond
Software Developer | Baobab Health Trust (http://www.baobabhealth.org/)
|
Malawi

Cell: +265 999 465 137 | +265 881 234 717

Prosperous New Year 2011 and Prosperous New Decade!!

I often use inject method (where and when I want to. Lol!). I would like to
know the difference between inject and reduce methods. I find them similar.

They are the same. reduce is an alias for inject.

On Thu, Jan 13, 2011 at 1:59 AM, Edmond K. <
[email protected]> wrote:

Malawi

Cell: +265 999 465 137 | +265 881 234 717

Prosperous New Year 2011 and Prosperous New Decade!!

They are the same, I think the names are just to make people from
different
languages feel at home. I think “inject” is from Smalltalk, and “reduce”
is
from Common Lisp, and IIRC “fold” is from Scheme and Haskell.

Interestingly, at the last RubyConf, Aaron P. and Rein H.
were
giving their presentations simultaneously, in different rooms, and both
of
them criticized the use of this method :stuck_out_tongue:

On Thu, Jan 13, 2011 at 6:30 AM, Josh C. [email protected]
wrote:

They are the same, I think the names are just to make people from different
languages feel at home. I think “inject” is from Smalltalk, and “reduce” is
from Common Lisp, and IIRC “fold” is from Scheme and Haskell.

Interestingly, at the last RubyConf, Aaron P. and Rein H. were
giving their presentations simultaneously, in different rooms, and both of
them criticized the use of this method :stuck_out_tongue:

http://talklikeaduck.denhaven2.com/2010/11/26/how-arlo-got-injected-into-ruby


Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Github: http://github.com/rubyredrick
Twitter: @RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

Rick DeNatale wrote:

http://talklikeaduck.denhaven2.com/2010/11/26/how-arlo-got-injected-into-ruby

Note that Iverson’s notation in “A Programming Language”(Wiley, 1962)
contained “reduction” operations to extend an operation such as
multiplication over all components of a vector or matrix. APL
programmers commonly pronounce an expression like “+/v” as “plus reduce
v”.

Thanks for the Alice’s Restaurant connection.

– Bill

On Thu, Jan 13, 2011 at 6:33 AM, Rick DeNatale
[email protected]wrote:

giving their presentations simultaneously, in different rooms, and both
of
them criticized the use of this method :stuck_out_tongue:

http://talklikeaduck.denhaven2.com/2010/11/26/how-arlo-got-injected-into-ruby

Hah, I went and listened to that song, it was awesome!