2

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

4
  • 1
    The 2 keys concepts of functionnal programming are 'function are objects' and 'immutability' Commented Sep 5, 2016 at 16:11
  • then, the best implementation should be to have a mutable map and then transform this map to a new one by sorting it. ?
    – ypriverol
    Commented Sep 5, 2016 at 16:16
  • However, @Jasper-M scala has mutable collections mutable.Map, etc.
    – ypriverol
    Commented Sep 5, 2016 at 16:18
  • Looks like it's implemented in 2.12: github.com/scala/scala/blob/v2.12.0-M4/src/library/scala/… Commented Sep 5, 2016 at 16:51

2 Answers 2

6

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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.