What is the difference between inject and reduce methods

E

Edmond Kachale

[Note: parts of this message were removed to make it a legal post.]

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!!*
 
A

Anurag Priyam

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.
 
J

Josh Cheek

[Note: parts of this message were removed to make it a legal post.]

On Thu, Jan 13, 2011 at 1:59 AM, Edmond Kachale <
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!!*


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 Patterson and Rein Henrichs were
giving their presentations simultaneously, in different rooms, and both of
them criticized the use of this method :p
 
R

Rick DeNatale

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 Patterson and Rein Henrichs were
giving their presentations simultaneously, in different rooms, and both of
them criticized the use of this method :p

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,588
Members
45,093
Latest member
Vinaykumarnevatia00

Latest Threads

Top