0

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?

EDIT:

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.

Ashkan Kh. Nazary
  • 21,844
  • 13
  • 44
  • 68

1 Answers1

0

I think you are looking for this

  val hands : collection.Seq[Team] with Growable[Team] = mutable.Buffer[Team]()
Jonas Anso
  • 2,057
  • 14
  • 13