Re : What about a 'series' type?

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

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: [email protected] / [email protected]
blog: http://etorreborre.blogspot.com

----- Message d’origine ----
De : Robert D. [email protected]
À : ruby-talk ML [email protected]
Envoyé le : Jeudi, 7 Juin 2007, 20h29mn 46s
Objet : Re: What about a ‘series’ type?

On 6/7/07, Peter M. [email protected] 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 :wink:
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
http://fr.answers.yahoo.com

Pls no top post
On 6/7/07, Eric T. [email protected] wrote:

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

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

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 :wink:

Cheers
Robert

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs