3 ms·
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?
by Peaker 16y ago
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?
- kejadlen 16y agoBy default, inject uses the first element of the array as the argument, so it would use nil on an empty list. It optionally takes an argument to kick off the process.
- kragen 16y agoThe 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.