hg: lambda/lambda/jdk: Modify Iterables.uniqueElements to be fully lazy.

Stuart Marks stuart.marks at oracle.com
Wed May 2 14:28:01 PDT 2012


On 4/13/12 4:12 PM, Rémi Forax wrote:
> On 04/14/2012 12:23 AM, stuart.marks at oracle.com wrote:
>> Changeset: 08c12c22393c
>> Author:    smarks
>> Date:      2012-04-13 15:24 -0700
>> URL:       http://hg.openjdk.java.net/lambda/lambda/jdk/rev/08c12c22393c
>>
>> Modify Iterables.uniqueElements to be fully lazy.
>
> Hi Stuart,
> null should be an allowed value.
> It's really easy to implement it with a null object.
> Also I think it's better to let the user choose which Set he wants to use
> (the equals semantics is not always the best).
>
> So the code should be something like this: [...]

Hi, finally getting back to this.

 From Brian's other notes you might have gathered that we're generally leaning 
against supporting null values. But it's good to know that using the null 
object technique can be used to implement it if we choose to do so.

Good point also about allowing the caller to choose a different set 
implementation. The most obvious alternative would be IdentityHashSet which -- 
doh! -- doesn't exist in the JDK, but which has been implemented elsewhere 
several times. Mike Duigou also pointed out that if the stream is known to be 
sorted, maintaining a set isn't necessary at all. Another alternative is to 
have the caller pass in a Factory instead of an instance.

I'll add this to our issues list but I don't think I'll proceed with this at 
the moment.

s'marks



More information about the lambda-dev mailing list