用于遍历列表或树的拉链与迭代器 [英] Zipper vs. iterator for walking over a list or tree

查看:44
本文介绍了用于遍历列表或树的拉链与迭代器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我需要遍历一个列表或树来读取(但不修改)数据.我可以使用迭代器或 Zipper.在这种情况下,Zipper 除了不变性之外还有什么优势吗?

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?

推荐答案

您是否需要以非顺序顺序回溯或以其他方式在结构中移动?您是否希望能够多次遍历结构而不必担心从哪里离开迭代?您想避免考虑并发访问或线程安全吗?带上拉链.

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.

这篇关于用于遍历列表或树的拉链与迭代器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆