Design for collections upgrades
Rémi Forax
forax at univ-mlv.fr
Mon Mar 14 07:20:28 PDT 2011
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