# SyncEnumerator

**URL:** <https://rubytalk.org/t/syncenumerator/14685>\
**Category:** ruby-talk\
**Created:** [9 November 2004 13:06 UTC](https://rubytalk.org/t/syncenumerator/14685 "2004-11-09T13:06:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SER](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@SER](https://rubytalk.org/u/SER)\
**Post date:** [9 November 2004 13:06 UTC](https://rubytalk.org/t/syncenumerator/14685/1 "2004-11-09T13:06:58Z")

</div>

Ok. Then I'd like to suggest replacing the existing SyncEnumerator in  
Generator.rb with the one I've provided.

> **···**
>
> On Sunday 07 November 2004 17:49, Yukihiro Matsumoto wrote:
> 
> > &nbsp;&nbsp;&nbsp;&nbsp;on Mon, 8 Nov 2004 04:08:36 +0900, gabriele renzi  
> > &nbsp;&nbsp;&nbsp;&nbsp;\> \>but /just/ making something faster seems a ruby-core thing, cause it  
> > &nbsp;&nbsp;&nbsp;&nbsp;\> \>is  
> > &nbsp;&nbsp;&nbsp;&nbsp;\> \>better in everyone's point of view (well, except for making  
> > &nbsp;&nbsp;&nbsp;&nbsp;\> \>sleep()  
> > &nbsp;&nbsp;&nbsp;&nbsp;\> \> faster)
> > 
> > I thing making something faster without changing behavior would do  
> > nothing with RCR from the beginning.
> 
> --  
> ### SER  
> ### Deutsch|Esperanto|Francaise|Linux|XML|Java|Ruby|Aikido  
> ### [http://www.germane-software.com/~ser](http://www.germane-software.com/~ser) jabber.com:ser ICQ:83578737  
> ### GPG: [http://www.germane-software.com/~ser/Security/ser\_public.gpg](http://www.germane-software.com/~ser/Security/ser_public.gpg)

---

<div class="post-metadata">

**Author:** ![Carlos](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@Carlos](https://rubytalk.org/u/Carlos)\
**Post date:** [10 November 2004 12:17 UTC](https://rubytalk.org/t/syncenumerator/14685/2 "2004-11-10T12:17:29Z")

</div>

["Sean E. Russell" \<ggg@ser1.net\>, 2004-11-09 14.06 CET]

> Ok. Then I'd like to suggest replacing the existing SyncEnumerator in  
> Generator.rb with the one I've provided.

But:

&nbsp;&nbsp;class SyncEnumerator2  
&nbsp;&nbsp;&nbsp;&nbsp;...  
&nbsp;&nbsp;end

&nbsp;&nbsp;f = File.new("/etc/passwd")  
&nbsp;&nbsp;g = 0..10  
&nbsp;&nbsp;SyncEnumerator2.new(f, g).each do |line, nr| print nr, ": ", line end

produces:

&nbsp;&nbsp;p.rb:11:in `initialize': undefined method `size' for #\<File:/etc/passwd\> (NoMethodError)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from p.rb:11:in `each'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from p.rb:11:in `initialize'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from p.rb:37:in `new'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from p.rb:37

> **···**
>
> --

---

<div class="post-metadata">

**Author:** ![Jonathan\_Paisley](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@Jonathan\_Paisley](https://rubytalk.org/u/Jonathan_Paisley)\
**Post date:** [10 November 2004 12:53 UTC](https://rubytalk.org/t/syncenumerator/14685/3 "2004-11-10T12:53:30Z")

</div>

Is the SyncEnumerator method 'end?' from the original implementation in  
generator.rb part of the public interface? If so, is it okay that the  
proposed alternative doesn't provide it?

Another difference that may be worth considering is that the  
non-continuation based implementation can't (I think - please correct me  
here) handle Enumerables that can only be enumerated once. An example  
would be a file, socket or a pipe.

SyncEnumerator1 uses to index the Enumerable, so it would be  
necessary to update the documentation to explicitly indicate that objects  
supporting are required. The same applies for the use of the 'size'  
method.

SyncEnumerator2 uses zip which converts to arrays internally if necessary.  
What are the memory implications of using SyncEnumerator2 as opposed to  
the current SyncEnumerator with, for example, two very large files?

I suppose the above boils down to: the SyncEnumerator improvements  
primarily apply to array-like objects, so I'd like to see the  
Generator-based implementation remain, somewhere.

Thanks.

> **···**
>
> On Tue, 09 Nov 2004 22:06:58 +0900, Sean E. Russell wrote:
> 
> > On Sunday 07 November 2004 17:49, Yukihiro Matsumoto wrote:
> > 
> > > I thing making something faster without changing behavior would do  
> > > nothing with RCR from the beginning.
> > 
> > Ok. Then I'd like to suggest replacing the existing SyncEnumerator in  
> > Generator.rb with the one I've provided.

---

<div class="post-metadata">

**Author:** ![T\_Onoma](https://avatars.discourse-cdn.com/v4/letter/t/c2a13f/32.png) [@T\_Onoma](https://rubytalk.org/u/T_Onoma)\
**Post date:** [10 November 2004 13:36 UTC](https://rubytalk.org/t/syncenumerator/14685/4 "2004-11-10T13:36:16Z")

</div>

Speaking of which, I tend to think #begin and #end, and the like named methods  
make terrible method names. Do others agree? Should these be dprecated in  
favor of others?

T.

> **···**
>
> On Wednesday 10 November 2004 07:53 am, Jonathan Paisley wrote:
> 
> > Is the SyncEnumerator method 'end?' from the original implementation in  
> > generator.rb part of the public interface? If so, is it okay that the  
> > proposed alternative doesn't provide it?
