On Nov 28, 10:53 am, "Just Another Victim of the Ambient Morality"
<ihates... / hotmail.com> wrote:
> "MonkeeSage" <MonkeeS... / gmail.com> wrote in message
>
> news:4f89dee4-b922-49ef-889f-e281e7ad0e8c / j44g2000hsj.googlegroups.com...
>
>
>
> > On Nov 28, 9:19 am, MonkeeSage <MonkeeS... / gmail.com> wrote:
> >> ========
>
> >> require 'generator'
>
> >> module Enumerable
> >>   def izip(*enumerables)
> >>     enumerables = [self] + enumerables
> >>     generators = enumerables.map { | enum |
> >>       Generator.new(enum)
> >>     }
> >>     while generators[0].next?
> >>       result = generators.map { | gen |
> >>         gen.next
> >>       }
> >>       yield result
> >>     end
> >>   end
> >> end
>
> >> [1,2,3].izip([4,5,6]) { | x, y |
> >>   puts x, y
>
> >> }
>
> >> ========
>
> >> NB. generator.rb says that generators are slow in 1.8.
>
> >> Regards,
> >> Jordan
>
> > Ps. The SyncEnumerator class from generator does the same thing as
> > izip:
>
> > SyncEnumerator.new([1,2,3], [4,5,6]).each { | x, y |
> >  puts x, y
> > }
>
>     Thank you, MonkeeSage, this is exactly what I'm looking for!
>     It's interesting that generators are slow enough to warn users about its
> lack of speed!  Do you know if it would be any faster implemented with
> continuations?  I'm surprised it's so slow considering Ruby employs green
> threads...

Other way around. ;) The continuation version is slow. The threaded
version is fast.