Home Ask Login Register

Developers Planet

Your answer is one click away!

ashy_32bit February 2016

A (strictly) `Growable` mutable `Seq`

I need a (mutable) Seq that is only Growable. I do not need to update any index or shrink the collection or transform it (or any other form of mutation), Just grow it (+=) and I want to actively protect the collection from other mutations.

  • The problem with Buffers is that they are not just Growable but also Shrinkable and can be transformed.
  • (mutable.)Seq is not Shrinkable but it can transform and it is not Growable

To my (cursory) understanding of scala collection, there is no concrete implementation that has the exact traits that I'm looking for so I believe I have to implement my own?


I tried val hands : collection.Seq[Team] with Growable[Team] = mutable.Seq[Team]() in an attempt to make the nominal type conform to my requirements, actively preventing the client to call the undesired mutating methods on hands but it says types does not conform.


JonasAnso February 2016

I think you are looking for this

  val hands : collection.Seq[Team] with Growable[Team] = mutable.Buffer[Team]()

Post Status

Asked in February 2016
Viewed 1,364 times
Voted 12
Answered 1 times


Leave an answer

Quote of the day: live life