IntStreams and the case of the missing reduce

Remi Forax forax at univ-mlv.fr
Tue Jan 7 05:34:41 PST 2014


On 01/07/2014 01:49 PM, Richard Warburton wrote:
> Hi,
>
> Yes it would.  And because of one extra type we lost the symmetry between
>> the primitive and object streams, and lost the most useful reduce method
>> for raw streams.  I would call that the poorer choice.  The existence of
>> the distinction between primitives and objects in Java is annoying enough
>> as it is -- what's the point of exasperating it by building interfaces with
>> asymmetrys and missing methods for the primitives vs objects.
>>
> I think the thing you need to consider is whenever you say "one more
> functional interface" for primitives its really 3 since you need to cover
> int/long/double. And if you need to specialise by two arguments which might
> be different (eg: zip) then its 9 interfaces.
>
> If you look at the API as a whole there are compromises, especially around
> primitives. The real solution to the primitive problems is a unified type
> system rather than adding loads more functional interfaces. Hopefully this
> will be a focus of development in Java 9.

Hi Richard,
a unified type system, is not enough, you also need a unified runtime 
class system,
by example, you have a method sum() on IntStream, suppose you want
to declare sum() on Stream, you need to declare that int is a 
Comparable<int>,
and you also need 'conditional generics', something that say that the 
method sum
exist if the element are comparable and have a zero.

while some form of unified type system can be introduced in 9,
we will still need IntStream.

>
> regards,
>
>    Richard Warburton
>
>    http://insightfullogic.com
>    @RichardWarburto <http://twitter.com/richardwarburto>
>

cheers,
Rémi



More information about the lambda-dev mailing list