[ruby-talk:02386] Re: Iterator into array

From: Dave Thomas <Dave@...>
Date: 2000-04-07 20:34:50 UTC
List: ruby-talk #2386
mengx@nielsenmedia.com writes:

> > True, but that then means that every iterator would have to implement
> > the test. It would seem better to make the implementation part of the
> > general set of collections, rather than of the methods that fill them.
> > 
> 
> Maybe 
> 
> result = Array.new(iterator) 
> would work if Array can check its type.

That would be nice, although it would have to be something uglier such 
as
      Array.new(method(:fibUpTo))


I'm beginning to wonder about the idea that a method that calls yield
with no block present returns an array of yielded values.  You'd have
to flag the call to indicate that this was the behavior you wanted
(otherwise we'd have compatibility problems). Perhaps (being
symmetrical) you might write something such as

     fibUpTo*(20)

where the '*' indicates that an array result is required.



Dave

In This Thread

Prev Next