Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zipper vs. iterator for walking over a list or tree

Tags:

scala

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?

like image 673
Michael Avatar asked Jun 01 '14 13:06

Michael


1 Answers

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.

like image 167
Travis Brown Avatar answered Nov 02 '22 04:11

Travis Brown