Why no immutable double linked list in Scala collections?

后端 未结 5 695
轻奢々
轻奢々 2021-02-05 16:33

Looking at this question, where the questioner is interested in the first and last instances of some element in a List, it seems a more efficient solution would be

5条回答
  •  Happy的楠姐
    2021-02-05 17:15

    Because you would have to copy the whole list each time you want to make a change. With a normal linked list, you can at least prepend to the list without having to copy everything. And if you do want to copy everything on every change, you don't need a linked list for that. You can just use an immutable array.

提交回复
热议问题