Right way of implementing filter on a hierarchy of collection

Dear All,
I am a little bit confused from self type and generics.
I have to implement a hiearchy of custom generic collection implementing a filter function, and of course I want that each collection when filtered return a collection of the same type.
What is the right way to implement this?
Best Regards
Edmondo

Re: Right way of implementing filter on a hierarchy of collecti

On Fri, Jan 13, 2012 at 11:16, Edmondo Porcu wrote:
> Dear All,
>
> I am a little bit confused from self type and generics.
>
> I have to implement a hiearchy of custom generic collection implementing a
> filter function, and of course I want that each collection when filtered
> return a collection of the same type.
>
> What is the right way to implement this?

The default implementation of "filter" in TraversableLike uses the
protected method "newBuilder". So you need three things:

1. Extend TraversableLike[A, YourCollectionHere]
2. Override this method:

protected[this] def newBuilder: Builder[A, Repr]

3. Create a Builder for your class.

Copyright © 2013 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland