Why are Scala's `Lists` implemented as linked lists

后端 未结 5 1494
闹比i
闹比i 2021-02-19 05:49

I always thought that the benefit of linked lists was that you could add or remove items (especially not from the end) without having to copy lots of elements thanks to the beau

5条回答
  •  面向向阳花
    2021-02-19 06:27

    Structural sharing. If you perform a higher-order function (map, fold, etc) on the list, you return a new instance of a list that shares the pointers of the previous list.

    Daniel Spiewak did a marvelous presentation about functional data structures at NE Scala last week. See here: http://www.nescala.org/2011/

提交回复
热议问题