Re:Joel Spolsky: Can your programming language do this?
by SandB0x on Saturday April 23, 2011 @04:55AM
(#2476525)
In Ruby the reduce method is also called reduce:
[ Parent
| on HN ]
Re:Joel Spolsky: Can your programming language do this?
by JonnieCache on Saturday April 23, 2011 @05:02AM
(#2476532)
Reduce is an alias for inject, and depending on which template you use to generate the docs, method aliases are not given the same prominence as full methods. Some templates simply say "this method is also known as..." underneath the original method in a tiny font.
If it were the other way around, and inject was an alias for reduce, I think there would be a lot less confused rubyists.
Re:Joel Spolsky: Can your programming language do this?
by DanielRibeiro on Saturday April 23, 2011 @10:56AM
(#2476906)
I've wrote about these ancient ways of great languages a while ago: http://metaphysicaldeveloper.wordpress.com/2009/05/02/closur...
Re:Joel Spolsky: Can your programming language do this?
by Peaker on Saturday April 23, 2011 @12:15PM
(#2477054)
What would it do on an empty list? It should probably take an argument for the empty case...
What is the history behind the name "inject" here?
Re:Joel Spolsky: Can your programming language do this?
by kragen on Saturday April 23, 2011 @01:33PM
(#2477186)
The name comes from Smalltalk. I imagine that the idea is that you're "injecting" an operator between items in the list: 1 2 3 4 becomes 1 + 2 + 3 + 4.