Hi --

On Sat, 26 Sep 2009, Marc-Andre Lafortune wrote:

> For what it's worth, although solution 3 is not very pretty, it could
> be done with a simple change to the documentation stating that one
> should call #rewind to insure resources are released (or let the
> enumerator fall out of scope so the GC takes care of it). When an
> enumerator is rewound, implementations are free to stop the associated
> thread. Of course, if a subsequent call to #next is made, a new one
> needs to be started (so a small delay might be in order before
> shutting down the thread, etc...)
>
> I'm curious as to what are good examples of uses of #next. Personally,
> I don't mind the fact that its use comes with a big warning "might be
> slow or unsupported".

One idiom I've seen is:

   a = [1,2,3].each

   [4,5,6].each do |n|
     p n + a.next
   end

i.e., as a way to do parallel iterators. (Of course that particular
example could be done with zip.)


David

-- 
David A. Black, Director
Ruby Power and Light, LLC (http://www.rubypal.com)
Ruby/Rails training, consulting, mentoring, code review
Book: The Well-Grounded Rubyist (http://www.manning.com/black2)