From: Peter Marsh Date: 2007-06-07T23:47:41+09:00 Subject: Re: What about a 'series' type? SonOfLilit wrote: > Actually, the syntax: > > a = Series.new(8) {|i| 5*i**3} > > a.collect{|i| i + 1}.select{|i| i % 2 == 0} # i.e. a is an enumerable > object > > is quite cool and might be useful in some cases. The only problem I'm > trying to solve is that of providing syntax for persistence (e.g. try > to implement a series of Fibonacci numbers with the iterative > algorithm using this Series syntax). Perhaps an optional hash argument > that is used to give initial values to instance variables? > > With persistence, this could be a very useful idiom in many cases, and > maybe even deserves to be stdlib. > > Aur The two examples I gave are fairly specific, I didn't really think about that. However, I still think a 'series' type would be useful, even if the implimentation is different to my example. Taking prime numbers as an example using the current 'prime' class you have to use: require 'mathn' primes = Prime.new etc With a seires type you could do something like this: primes = Series.new(Starting_value,Some_block_to_define_serires) primes[0] = 2 primes[0..2] >> [2,3,5] Giving definate advantages, I feel. -- Posted via http://www.ruby-forum.com/.