module Enumerable
 def serially(&b)
   a = []
   self.each{|x| t = [x].instance_eval(&b); a << t[0] unless t.empty?}
   a
 end
end

p (0..20).serially{select{|x| x>10}.collect{|x|"0x" <<
x.to_s}.select{|x| x != "0x15"}}

#=> ["0x11", "0x12", "0x13", "0x14", "0x16", "0x17", "0x18", "0x19", "0x20"]

The original version was written in another computer, and re-typing
wuthout testing took it's toll. I'm really sorry for wasting all of
your times.

On the other hand, I seem to have inspired someone to think of a
really clever hack, that is exactly orthogonal to my method:

While I call all methods on each member of the enumerable,
incrementally building the results array (a bit like using Generator
iterators, but without the continuations :P), Brad evaluates each
function in the chain on 100 members at a time, building the array for
the next function. If he'd use slices of size 1, our code would be
very similar in idea. My attempt to combine our methods ended in
finding that my installed Enumerable implementation is braindead,
probably a collision between the 1.8.5 and 1.8.2 ruby versions
installed here. I don't care enough to go into it right now.

Profiling data is on the way and will be here soon.

Aur

On 5/30/07, Brad Phelan <phelan / tttech.ttt> wrote:
> Brad Phelan wrote:
> > Brad Phelan wrote:
> >> Brian Candler wrote:
> >>> On Wed, May 30, 2007 at 10:46:33PM +0900, SonOfLilit wrote:
> >>>> Sorry, found a bug, I'll need to make it into this:
> >>>>
> >>>> module Enumerable
> >>>>  def serially(&b)
> >>>>    a = []
> >>>>    self.each{|x| t = ([x].instance_eval(&b); a << b[0] unless b.empty?}
> >>>>    # notice, relevance to "it" discussion that's currently going on,
> >>>> just    btw
> >>>>  end
> >>>> end
> >>>
> >>> Somehow I don't think you tested this :-)
> >>>
> >>> * You have mismatched parentheses
> >>> * You assign to t, but never use the value
> >>> * you call b twice, once with no arguments, and once with 0 as an
> >>> argument
> >>> * b is a block, but you call #empty? on it
> >>>
> >>> Can you give an example of how this is supposed to be used?
> >>>
> >>> Brian.
> >>>
> >>
> >> I think I get his point. I wrote a little lib to try out my
> >> interpretation of what he is trying to do.
> >>
> >>
> >> a = (1..20)
> >>
> >> b = a.serially do
> >>     select do |x|
> >>         if x > 10
> >>             true
> >>         else
> >>             false
> >>         end
> >>     end
> >>     collect do |x|
> >>         "0x" + x.to_s
> >>     end
> >>     select do |x|
> >>         if x == "0x15"
> >>             false
> >>         else
> >>             true
> >>         end
> >>     end
> >> end
> >>
> >> puts b
> >>
> >>
> >>
> >> # generates
> >>
> >> 0x11
> >> 0x12
> >> 0x13
> >> 0x14
> >> 0x16
> >> 0x17
> >> 0x18
> >> 0x19
> >> 0x20
> >>
> >> The lib is at
> >>
> >> http://xtargets.com/snippets/posts/show/69
> >>
> >> --
> >> Brad Phelan
> >> http://xtargets.com/snippets
> >>
> >
> > A quick profile with ruby-prof find the above technique about 10 times
> > slower in 50000 elements than for the traditional method.
> >
> > --
> > Brad Phelan
> > http://xtargets.com
>
> This little bit of code has got me interested. Turns out I can create a
> version with comparable time execution by slicing the the input
> enumerable into memory friendly chunks and then performing all
> operations on those chunks. This kind of reminds me of C++
> expression templating tricks
>
> See the link
>
> http://xtargets.com/snippets/posts/show/69
>
> for the latest highspeed version and the ruby-prof results
>
> --
> Brad Phelan
> http://xtargets.com
>
>