2015-12-02 15:03 GMT+01:00 Ben Coman <btc@openinworld.com>:
On Wed, Dec 2, 2015 at 12:38 AM, Tudor Girba <tudor@tudorgirba.com> wrote:
> Hi,
>
>> On Dec 1, 2015, at 5:13 PM, Max Leske <maxleske@gmail.com> wrote:
>>
>> @Doru
>> You���re missing the point: #anyOne *fails* for empty collections.
>
> I am not missing the point at all. I am saying that if you want sum: to be generic, it cannot assume a specific Zero object.
>
> And sum: should be generic because of its name.

I am missing understanding the other use cases.�� Can you describe
further the generic nature of #sum & #sum: ?�� I would have thought by
default they only applied to numbers.

sum can be applied to anything that supports #+, not only numbers
sum: can be applied to any collection with a block that return some object that supports #+

therefore you can not assume 0 (<- a number) is a proper initial value therefore you *need* to work with #anyOne
and as you can not assume a proper initial value, you can not assume a default value for empty collections
-> it should throw an error. If you (the caller of the function) knows what to do with an empty collection you have
to check, or call inject:into: directly, with a proper initial value.
��

cheers -ben

>
>>> On 01 Dec 2015, at 15:31, Esteban A. Maringolo <emaringolo@gmail.com> wrote:
>>>
>>> I don't want to be heretic (or too orthodox), but why not to delegate
>>> this behavior to other class (an iterator maybe?).
>>>
>>> It's too tempting adding these convenience methods to Collection
>>> and/or subclasses, but anything that requires an explicit protocol of
>>> its elements is wrong, IMO.
>>>
>>> something like aCollection arithmetic sum: [...] or.... aCollection
>>> arithmetic avg.
>>
>>
>> Interesting thought!
>
> +100
>
> Doru
>
>>>
>>> My two cents for this.
>>>
>>> Regards!
>>>
>>>
>>> Esteban A. Maringolo
>>>
>>
>>
>
> --
> www.tudorgirba.com
>
> "Every thing has its own flow."
>
>
>
>
>