# What is the difference between inject and reduce methods

**URL:** <https://www.ruby-forum.com/t/what-is-the-difference-between-inject-and-reduce-methods/201711>\
**Category:** Ruby\
**Created:** [January 13, 2011, 9:00am UTC](https://www.ruby-forum.com/t/what-is-the-difference-between-inject-and-reduce-methods/201711 "2011-01-13T09:00:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [January 13, 2011, 9:00am UTC](https://www.ruby-forum.com/t/what-is-the-difference-between-inject-and-reduce-methods/201711/1 "2011-01-13T09:00:20Z")

</div>

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: [module Enumerable - RDoc Documentation](http://www.ruby-doc.org/core/classes/Enumerable.html#M001495)

* * *

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

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

_Prosperous New Year 2011 and Prosperous New Decade!!_

---

<div class="post-metadata">

**Author:** ![ceekays](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@ceekays](https://www.ruby-forum.com/u/ceekays)\
**Post date:** [January 13, 2011, 9:08am UTC](https://www.ruby-forum.com/t/what-is-the-difference-between-inject-and-reduce-methods/201711/2 "2011-01-13T09:08:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ceekays](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@ceekays](https://www.ruby-forum.com/u/ceekays)\
**Post date:** [January 13, 2011, 12:30pm UTC](https://www.ruby-forum.com/t/what-is-the-difference-between-inject-and-reduce-methods/201711/3 "2011-01-13T12:30:41Z")

</div>

On Thu, Jan 13, 2011 at 1:59 AM, Edmond K. \<  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> 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 😛

---

<div class="post-metadata">

**Author:** ![ceekays](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@ceekays](https://www.ruby-forum.com/u/ceekays)\
**Post date:** [January 13, 2011, 1:38pm UTC](https://www.ruby-forum.com/t/what-is-the-difference-between-inject-and-reduce-methods/201711/4 "2011-01-13T13:38:41Z")

</div>

On Thu, Jan 13, 2011 at 6:30 AM, Josh C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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 😛

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

–  
Rick DeNatale

Blog: [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)  
Github: [rubyredrick (Rick DeNatale) · GitHub](http://github.com/rubyredrick)  
Twitter: @RickDeNatale  
WWR: [NameBright - Coming Soon](http://www.workingwithrails.com/person/9021-rick-denatale)  
LinkedIn: [http://www.linkedin.com/in/rickdenatale](http://www.linkedin.com/in/rickdenatale)

---

<div class="post-metadata">

**Author:** ![ceekays](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@ceekays](https://www.ruby-forum.com/u/ceekays)\
**Post date:** [January 13, 2011, 3:12pm UTC](https://www.ruby-forum.com/t/what-is-the-difference-between-inject-and-reduce-methods/201711/5 "2011-01-13T15:12:22Z")

</div>

Rick DeNatale wrote:

> > 
> 
> [http://talklikeaduck.denhaven2.com/2010/11/26/how-arlo-got-injected-into-ruby](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

---

<div class="post-metadata">

**Author:** ![ceekays](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@ceekays](https://www.ruby-forum.com/u/ceekays)\
**Post date:** [January 13, 2011, 11:21pm UTC](https://www.ruby-forum.com/t/what-is-the-difference-between-inject-and-reduce-methods/201711/6 "2011-01-13T23:21:48Z")

</div>

On Thu, Jan 13, 2011 at 6:33 AM, Rick DeNatale  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> > giving their presentations simultaneously, in different rooms, and both  
> > of  
> > them criticized the use of this method 😛
> 
> [http://talklikeaduck.denhaven2.com/2010/11/26/how-arlo-got-injected-into-ruby](http://talklikeaduck.denhaven2.com/2010/11/26/how-arlo-got-injected-into-ruby)

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