`
orcl_zhang
  • 浏览: 242318 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

ruby cookbook -- Looping Through Multiple Iterables in Parallel

    博客分类:
  • ruby
阅读更多
Recipe 7.9. Looping Through Multiple Iterables in Parallel
Any object that implements the each method can be wrapped in a Generator object. If you've used Java, think of a Generator as being like a Java Iterator object. It keeps track of where you are in a particular  iteration over a data structure.

Normally, when you pass a block into an iterator method like each, that block gets called for every element in the iterator without interruption. No code outside the block will run until the iterator is done iterating. You can stop the iteration by writing a break statement inside the code block, but you can't restart a broken iteration later from the same placeunless you use a Generator.
看看api
    Generator converts an internal iterator (i.e. an Enumerable object)
     to an external iterator.
==
generator更象是把ruby的内部迭代器实现成java中的外部跌代器,这样可以随时中断,并从中断的位置继续开始。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics