小编Dir*_*urs的帖子

How to stop iteration in a Enumerator::Lazy method?

I am trying to implement a take_until method for Ruby 2's Enumerator::Lazy class. It should work similar to take_while but instead stop iteration when the yielded block returns true. The result should include the item where the yielded block matches.

My question is how do I signal that the end of the iteration is reached? When using regular Enumerators you can raise the StopIteration error in an each method to signal the end of the iterator. But that doesn't seem …

ruby enumerator lazy-evaluation

6
推荐指数
1
解决办法
1400
查看次数

标签 统计

enumerator ×1

lazy-evaluation ×1

ruby ×1