Re: IntStream.sum
Remi Forax
forax at univ-mlv.fr
Wed Jan 16 07:53:58 PST 2013
My argument is when you reduce over integers, you want an integer as result, like int + int is an int.
Reducing over integers and get a long should not be the default behavior because it's not what people espect.
If someone want a long, using reduce is better because reduce require to pass an operator so user can choose the exact semantics he want, throwing an exception or using a BigInteger is perhaps better.
Rémi
Sent from my Phone
----- Reply message -----
From: "Paul Sandoz" <paul.sandoz at oracle.com>
To:
Cc: <lambda-libs-spec-experts at openjdk.java.net>
Subject: IntStream.sum
Date: Wed, Jan 16, 2013 14:53
On Jan 16, 2013, at 2:33 PM, Remi Forax <forax at univ-mlv.fr> wrote:
> On 01/16/2013 02:32 PM, Paul Sandoz wrote:
>> On Jan 16, 2013, at 2:15 PM, Remi Forax <forax at univ-mlv.fr> wrote:
>>>> And long can hold the result of MAXINT additions?
>>>>
>>> stream are sized is store in a long if a size if definite or can be infinite
>>> so it solves nothing.
>>>
>> I don't quite understand the above sentence. Are you suggesting reducing/folding on a infinite stream?
>
> yes, and you throw an exception when you've done, Brian talk about that.
>
Well don't reduce/fold on a infinite stream :-)
I don't really buy into your argument that because there might be streams of size > Integer.MAX_VALUE that it implies sum() solves nothing, seems a rather extreme position to take. Do you think sum() solves nothing regardless of whether it returns an int or long?
Paul.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/lambda-libs-spec-experts/attachments/20130116/ec742e1b/attachment.html
More information about the lambda-libs-spec-experts
mailing list