sum of numbers using Primitives range

Arul Dhesiaseelan aruld at acm.org
Tue Dec 11 18:10:22 PST 2012


My bad, I was assuming inclusive. Thanks Brian.


On Tue, Dec 11, 2012 at 3:55 PM, Brian Goetz <brian.goetz at oracle.com> wrote:

> 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = 45.  Ranges are half-open.  As in,
>
>   for (int i=0; i<10; i++) { ... }
>
>
>
>
> On 12/11/2012 8:46 PM, Arul Dhesiaseelan wrote:
>
>> Sum of integers over using a Primitives range returns invalid result.
>>
>>      range(1, 10).map(operand -> operand).sum();
>>      range(1, 10).reduce(0, Integer::sum);
>>      range(1, 10).sum();
>>
>>
>> They all yield 45, instead of 55. Is this a bug?
>>
>> -Arul
>>
>>


More information about the lambda-dev mailing list