map and reduce functions on list

Venkat Subramaniam venkats at agiledeveloper.com
Mon Dec 10 09:52:57 PST 2012


Paul and Brian,

Thanks for the response and the explanation. Other than a minor loss of conciseness, this seems to be working out fairly well.
I don't feel any burden going through the stream. It certainly helped to learn the "why" behind it - thanks.

Regards,

Venkat

On Dec 10, 2012, at 10:45 AM, Brian Goetz <brian.goetz at oracle.com> wrote:

> Yes, this is a common question.  The short answer is no.
> 
> The reason is: Iterable has strong associations with "something that can be iterated multiple times" (even though the spec doesn't come right out and say that.)  Streams are more like IteratOR than IteraBLE.  But some stream sources might be fed by IO, and would not be Iterable.  Having the stream methods on Iterable led to multiple forms of confusion.  (We got a lot of confused queries along the line of "how do I know whether the collection is in eager or lazy mode?"  Obviously this doesn't make sense, but if this is what stuffing the methods into Iterable makes people think, that's a bad sign.)
> 
> Further, if the methods were on Iterable, then Collection would have a mix of eager and lazy methods with similar names, and the net result would be very confusing.  For example, filter(Predicate) is lazy and creates a new Stream, but removeAll(Predicate) mutates the collection in-place.  A user hitting ctrl-space would then have to reason about which are the "mutative old" method and which are the "functional new" ones.  Not what we were trying to do.
> 
> The syntactic overhead of the stream() call is regrettable -- it took us a long time to get over it too -- but once you get past the distaste, the resulting model is dramatically cleaner.
> 
> On 12/10/2012 12:04 PM, Venkat Subramaniam wrote:
>> Greetings,
>> 
>> Currently playing with b67 build and having a great time with it.
>> 
>> To use the map and reduce functions on a list, I'm calling the stream() method first
>> on a list. It would be convenient to have these methods directly on an Iterable (like
>> it was in a version a few months ago). Are there plans to bring these methods
>> back on Iterable or is doing the conversion to Stream the path forward.
>> 
>> My sincere apologies if this was discussed earlier and I totally missed it (a quick scan on
>> the list did not help me find the discussion). Much appreciate the response.
>> 
>> Thank you
>> 
>> Venkat
>> 



More information about the lambda-dev mailing list