Design for collections upgrades
Craig P. Motlin
motlin at gmail.com
Mon Mar 14 08:51:05 PDT 2011
Sorry I was talking about Scala. My phone changed it to "scalable"
On Mar 14, 2011 11:44 AM, "Rémi Forax" <forax at univ-mlv.fr> wrote:
> On 03/14/2011 04:41 PM, Craig P. Motlin wrote:
>>
>> In the Scalable implementation, both println statements print the same
>> thing. Yes that's confusing, but its very similar to mutating a
>> collection while working with lazy evaluation.
>>
>
> No, in Java you will get a fail fast ConcurrentModificationException
> if you mutate during a lazy evaluation.
>
> Rémi
>
>> On Mar 14, 2011 10:39 AM, "Rémi Forax" <forax at univ-mlv.fr
>> <mailto:forax at univ-mlv.fr>> wrote:
>> > On 03/14/2011 02:30 PM, Craig P. Motlin wrote:
>> >> There are two forms of lazy evaluation and I see people using the
>> same term
>> >> (Stream) to refer to both. In Scala they are called view and stream
>> and I
>> >> was confused about the difference so I asked on Stack Overflow.
>> Basically
>> >> the difference is:
>> >> In a view elements are recomputed each time they are accessed. In a
>> stream
>> >> elements are retained as they are evaluated.
>> >>
>> >> I think that Java collections ought to support both, which is
>> another reason
>> >> I think that eager ought to be the default. See the full
>> explanation here:
>> >>
>>
http://stackoverflow.com/questions/2282754/what-is-the-difference-between-a-view-and-a-stream
>> >
>> > Interresting.
>> > But memoization is hard to provide when your original collection is
>> mutable:
>> >
>> > What does this code print ?
>> >
>> > LinkedList<Integer> list = new LinkedList<>();
>> > Collections.addAll(list, 1, 2, 3, 4, 5);
>> > List<Integer> list2 = list.asScalaStreamPlease();
>> > System.out.println(list2.join(" ")); // the whole list is now memoized
>> >
>> > list.remove(0); // wink wink
>> > System.out.println(list2.join(" "));
>> >
>> > Rémi
>> >
>> >
>
More information about the lambda-dev
mailing list