How do I implement a collection in Scala 2.8?

Posted by Simon Reinhardt on Stack Overflow See other posts from Stack Overflow or by Simon Reinhardt
Published on 2010-03-28T22:48:53Z Indexed on 2010/03/28 22:53 UTC
Read the original article Hit count: 234

Filed under:
|
|
|

In trying to write an API I'm struggling with Scala's collections in 2.8(.0-beta1).

Basically what I need is to write something that:

  • adds functionality to immutable sets of a certain type
  • where all methods like filter and map return a collection of the same type without having to override everything (which is why I went for 2.8 in the first place)
  • where all collections you gain through those methods are constructed with the same parameters the original collection had (similar to how SortedSet hands through an ordering via implicits)
  • which is still a trait in itself, independent of any set implementations.

Additionally I want to define a default implementation, for example based on a HashSet. The companion object of the trait might use this default implementation. I'm not sure yet if I need the full power of builder factories to map my collection type to other collection types.

I read the paper on the redesign of the collections API but it seems like things have changed a bit since then and I'm missing some details in there. I've also digged through the collections source code but I'm not sure it's very consistent yet.

Ideally what I'd like to see is either a hands-on tutorial that tells me step-by-step just the bits that I need or an extensive description of all the details so I can judge myself which bits I need. I liked the chapter on object equality in "Programming in Scala". :-)
But I appreciate any pointers to documentation or examples that help me understand the new collections design better.

© Stack Overflow or respective owner

Related posts about scala

Related posts about collections