Why no immutable double linked list in Scala collections?

后端 未结 5 721
轻奢々
轻奢々 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条回答
  •  没有蜡笔的小新
    2021-02-05 17:32

    Because it is logically impossible to create a mutually (circular) referential data-structure with strict immutability.

    You cannot create two nodes that point to each other due to simple existential ordering priority, in that at least one of the nodes will not exist when the other is created.

    It is possible to get this circularity with tricks involving laziness (which is implemented with mutation), but the real question then becomes why you would want this thing in the first place?

提交回复
热议问题