# Re : What about a 'series' type?

**URL:** <https://www.ruby-forum.com/t/re-what-about-a-series-type/106215>\
**Category:** Ruby\
**Created:** [June 7, 2007, 5:04pm UTC](https://www.ruby-forum.com/t/re-what-about-a-series-type/106215 "2007-06-07T17:04:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kuyarico](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e36b37/32.png) [@kuyarico](https://www.ruby-forum.com/u/kuyarico)\
**Post date:** [June 7, 2007, 5:04pm UTC](https://www.ruby-forum.com/t/re-what-about-a-series-type/106215/1 "2007-06-07T17:04:45Z")

</div>

There is a complete lazy list implementation from Reginald Braithwaite  
website:

[http://raganwald.com/source/lazy\_lists.html](http://raganwald.com/source/lazy_lists.html)

It supports a lot of operations on this kind of “infinite” structures  
such as merge and cartesian product.

That one could make it to the core!

Eric.

* * *

## Eric TORREBORRE tel: +81 (0)90 5580 3280 e-mail: removed\_email\_address@domain.invalid / removed\_email\_address@domain.invalid blog: [http://etorreborre.blogspot.com](http://etorreborre.blogspot.com)

----- Message d’origine ----  
De : Robert D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
À : ruby-talk ML [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Envoyé le : Jeudi, 7 Juin 2007, 20h29mn 46s  
Objet : Re: What about a ‘series’ type?

On 6/7/07, Peter M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

Honestly I do not believe that the core is the place to put such  
things, furthermore I believe it is too specific a feature, a more  
general approach might have better chances to be fit for the core; Yet  
I do not think what follows is fit for the core either, but maybe you  
find it interesting or helpful:

class Lazy  
def initialize init, op, \*args  
@init = init  
@op = op  
@args = args.dup  
end

def upto value  
return [] if value \< 1  
(2…value).inject([@init]){ |acc,| acc \<\< acc.last.send( @op, \*@args  
) }  
end  
end # class Lazy

505/6 \> irb -r lazy.rb  
irb(main):001:0\> l = Lazy.new 1, :+, 2  
=\> #\<Lazy:0xb7ddfa60 @args=[2], @init=1, @op=:+\>  
irb(main):002:0\> l.upto 5  
=\> [1, 3, 5, 7, 9]  
irb(main):003:0\> m = Lazy.new 2, :_, 3  
=\> #\<Lazy:0xb7dd4908 @args=[3], @init=2, @op=:_\>  
irb(main):004:0\> m.upto 4  
=\> [2, 6, 18, 54]  
irb(main):005:0\>

Cheers  
Robert

## P.S. Implementations without #inject are theoretically possible 😉 R.

You see things; and you say Why?  
But I dream things that never were; and I say Why not?  
– George Bernard Shaw

* * *

Découvrez une nouvelle façon d’obtenir des réponses à toutes vos questions !  
Profitez des connaissances, des opinions et des expériences des  
internautes sur Yahoo! Questions/Réponses

> **[Yahoo | Mail, Weather, Search, Politics, News, Finance, Sports & Videos](https://www.yahoo.com/)**
>
> Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!

---

<div class="post-metadata">

**Author:** ![kuyarico](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e36b37/32.png) [@kuyarico](https://www.ruby-forum.com/u/kuyarico)\
**Post date:** [June 7, 2007, 5:19pm UTC](https://www.ruby-forum.com/t/re-what-about-a-series-type/106215/2 "2007-06-07T17:19:47Z")

</div>

Pls no top post  
On 6/7/07, Eric T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> There is a complete lazy list implementation from Reginald Braithwaite website:
> 
> [http://raganwald.com/source/lazy\_lists.html](http://raganwald.com/source/lazy_lists.html)
> 
> It supports a lot of operations on this kind of “infinite” structures such as merge and cartesian product.
> 
> That one could make it to the core!  
> Not to core, given the dependencies it has, however I would be the  
> first to strongly advocate Facets to be put into the stdlib [No I am  
> not involved with Factes ;)]  
> Stdlib would be the target than for everything using Factes.

And maybe the following is of interest too:  
[http://blog.grayproductions.net/articles/2006/02/20/infinite-streams](http://blog.grayproductions.net/articles/2006/02/20/infinite-streams)

Please do not look too closely at my toy code it was to show that the  
concept should be abstracted about and others have shown/done that  
much better 😉

Cheers  
Robert
