From: Martin DeMello Date: 2006-11-27T17:09:26+09:00 Subject: Re: ruby and list comprehension On 11/27/06, James Cunningham wrote: > > added = new_data.comprehend { |x| x if not old_data.include? x } > removed = old_data.comprehend { |x| x if not new_data.include? x } > same = new_data.comprehend { |x| x if old_data.include? x } I wrote http://zem.novylen.net/ruby/fproduct.rb a while ago to emulate list comprehensions in ruby - for example: for x,y,z in product 1..40, 1..40, proc {|x,y| x <= y}, 1..40, proc {|x,y,z| x**2 + y**2 == z**2} p [x,y,z] end The benefit is that the filters do get applied in order (sorted on arity), so that it doesn't generate all the combinations first and then filter. martin