Design for collections upgrades

Rémi Forax forax at univ-mlv.fr
Thu Mar 10 06:46:21 PST 2011


  Le 10/03/2011 15:27, Llewellyn Falco a écrit :
> Stop.

Do you really think you can stop me :)

> Iterable<T>   filter(Predicate<Boolean>  p)
>
> is the method.

I agree but not for the reason below.
In fact, it's more: Iterable<E> filter(Filter<? super E> filter)

> It should not and can not do the following
>
> Set s = myset.filter( #{s->s>  3} )
>
> why? because you can't change the signature to return a Set.

Java allows covariant return type. So you can.

> You could
> make it so you have this
>
> Set s = (Set)myset.filter( #{s->s>  3} )
>
> but then you run into the following with map
>
> assertEqual(3, new Set("a","b","c").map( #s->  s.length() ).count())
>
> how are you going to get that spec to pass?
> or will map do a fundamentally different thing than filter?

yes, map create can create a new collection with a type which is not
the type of the original collection.

> Llewellyn

Rémi



More information about the lambda-dev mailing list