1

I have been looking for options to implement a mutable sorted map in scala. I know I can store my data in a mutable map and then transformed into a sorted map if is needed or wrap the TreeMap from Java. However, Does anyone know why this is not implemented in scala? Is against any functional programming style?

Regards

ypriverol
  • 585
  • 2
  • 8
  • 28

2 Answers2

5

There is no reason but the omission of writing one. In fact, a mutable sorted map was added to Scala 2.12.x.

sjrd
  • 21,805
  • 2
  • 61
  • 91
1

There's some discussion in this old answer about possible reasons there isn't an implementation.

With regards to your second question, there are other mutable collections in Scala so I don't see any hard reason there couldn't be a mutable sorted map (see the older question as well). In a more general sense, functional programming can be taken to imply that mutable data is not used, and in this case a mutable sorted map would be avoided. However mutable collections may well be used "behind the scenes" in a library to improve performance, as long as they won't be visible to users of the library.

Community
  • 1
  • 1
trepidacious
  • 592
  • 4
  • 9