Zipper vs. iterator for walking over a list or tree

﹥>﹥吖頭↗ 提交于 2019-12-10 02:35:01

问题


Suppose I need to walk over a list or tree to read (but not modify) the data. I can use either an iterator or a Zipper. Does Zipper have any advantages aside from immutability in this case?


回答1:


Do you need to backtrack or otherwise move around in the structure in a non-sequential order? Do you want to be able to traverse the structure multiple times without worrying about where you left the iteration? Do you want to avoid thinking about concurrent access or thread safety? Go with the zipper.

Do you know for a fact that you need the extra performance an iterator can provide in some situations? Are you working on a team that doesn't want to learn about a new abstraction? Go with the iterator.



来源:https://stackoverflow.com/questions/23980275/zipper-vs-iterator-for-walking-over-a-list-or-tree

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!