The current docstring for reduce2 states:
The 2-argument version of reduce that does not take an initialization value. Instead, the first element of the array is used for initialization.
My reading of this is that it leaves unspecified what to do when ind is empty.
According to this commit, the current behavior of returning nil is intentional:
It seems like there are at least two other reasonable ways to handle an empty ind argument:
- Raise an error
- Try to call the
f argument with zero arguments
It seems that approach 2 is what Common Lisp went for [1].
If the current behavior is the most desirable, may be it would make sense to update the docstring?
[1] See this comment for more details.