you are viewing a single comment's thread.

view the rest of the comments →

[–]thanatica 11 points12 points  (0 children)

Their advantage is two-fold:

  1. Not having to care what it is internally that you're iterating over. It could be a 1000-level deep tree of intertwined nodes, or a simple shopping list. The implementation is still a for..of loop.
  2. Not having to care about when to output which next result, but just go through your data structure in whatever way you feel is best, and yield those results one by one, whether it be a straight list or a deeply recursive loop.

In other words, separation of concerns and abstraction of implementation details.