[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Command Pipeline (pipes & filters) in Ruby

eastcoastcoder

2/13/2006 5:31:00 AM

Anyone know of any generic implementation of a pipeline in ruby? That
is, one which takes a bunch of GoF Command objects, and strings them
together in the classical pipeline configuration.

Any advice on that?

I have a process with a lot of sequential processing, and think that a
pipeline of Command objects (not just Proc's) might be the way to do
it.

The downsides of pipelines:
1) You can't do selections (if) or sequences (loops). If you can
handle this, though, this becomes a virtue, as it keeps everything
crystal clear and simple. Witness the ever useful Unix command line
pipelines.

2) They don't encapsulate very well, as each stage totally overwrites
the previous ones. I'm not sure if I should just accept this, or try
to use some modification (append only pipeline, etc.).

Any experience or ideas on this appreciated.

16 Answers

james_b

2/13/2006 5:48:00 AM

0

eastcoastcoder@gmail.com wrote:
> Anyone know of any generic implementation of a pipeline in ruby? That
> is, one which takes a bunch of GoF Command objects, and strings them
> together in the classical pipeline configuration.
>
> Any advice on that?

Does Rake approach this?

Define each command as a task. Let Rake handle the chaining and
dependency logic.




--
James Britt

“Design depends largely on constraints.”
— Charles Eames


Robert Klemme

2/13/2006 9:32:00 AM

0

eastcoastcoder@gmail.com wrote:
> Anyone know of any generic implementation of a pipeline in ruby? That
> is, one which takes a bunch of GoF Command objects, and strings them
> together in the classical pipeline configuration.
>
> Any advice on that?
>
> I have a process with a lot of sequential processing, and think that a
> pipeline of Command objects (not just Proc's) might be the way to do
> it.
>
> The downsides of pipelines:
> 1) You can't do selections (if) or sequences (loops). If you can
> handle this, though, this becomes a virtue, as it keeps everything
> crystal clear and simple. Witness the ever useful Unix command line
> pipelines.
>
> 2) They don't encapsulate very well, as each stage totally overwrites
> the previous ones. I'm not sure if I should just accept this, or try
> to use some modification (append only pipeline, etc.).
>
> Any experience or ideas on this appreciated.

There are several ways you can do pipelining. Do you want concurrency
with that? Does every stage have a single output the next stage wants to
operate on? etc.

Probably the simplest thing you can do is to use #inject:

commands = [
lambda {|x| x * 2},
lambda {|x| 0 - x},
lambda {|x| x + 10},
]

>> commands.inject(0) {|x,cmd| cmd[x]}
=> 10
>> commands.inject(1) {|x,cmd| cmd[x]}
=> 8

Kind regards

robert

netghost

2/13/2006 4:40:00 PM

0

That's neat, this might be handy too:

class Proc
def |(other)
proc{|*a| other.call(self.call(*a)) }
end
end

I think I got the idea from something on Why's site, though I can't
find it now. Anyways if you could now do:

f = lambda {|x| x * 2} | lambda {|x| 0 - x} | lambda {|x| x + 10}

or more verbosely:

a = lambda {|x| x * 2}
b = lambda {|x| 0 - x}
c = lambda {|x| x + 10}

f = (a|b|c)

Think of it as unix pipes :)
.adam

Robert Klemme

2/13/2006 5:02:00 PM

0

Adam Sanderson wrote:
> That's neat, this might be handy too:
>
> class Proc
> def |(other)
> proc{|*a| other.call(self.call(*a)) }
> end
> end
>
> I think I got the idea from something on Why's site, though I can't
> find it now. Anyways if you could now do:
>
> f = lambda {|x| x * 2} | lambda {|x| 0 - x} | lambda {|x| x + 10}
>
> or more verbosely:
>
> a = lambda {|x| x * 2}
> b = lambda {|x| 0 - x}
> c = lambda {|x| x + 10}
>
> f = (a|b|c)
>
> Think of it as unix pipes :)
> .adam

Depending on the number of processors you might even run into stack size
limits which won't happen with an #inject based solution (see my other
posting). (Ok, I know that I'm being obsessive about Enumerable#inject -
it was love at first sight. :-)) )

Although this looks nice, when associating Unix pipes you might be tempted
to expect those to execute concurrently which they don't.

We can combine both solutions:

class ProcChain
def initialize(*procs) @chain = procs end
def |(proc)
@chain << proc
self
end
def call(a)
@chain.inject(a) {|x,pr| pr[x]}
end
alias [] call
end

class Proc
def |(proc)
ProcChain.new(self, proc)
end
end

irb(main):039:0> f = lambda {|x| x * 2} | lambda {|x| 0 - x} | lambda {|x|
x + 10}
=> #<ProcChain:0x4a6fed8 @chain=[#<Proc:0x04a70238@(irb):39>,
#<Proc:0x04a70148@(irb):39>, #<Proc:0x04a6ffc8@(irb):39>]>
irb(main):040:0> f[0]
=> 10
irb(main):041:0> f.call 1
=> 8

:-))

Kind regards

robert

t_shuffle

2/23/2008 3:50:00 AM

0



"Nelson" <nhenderson3@cogeco.ca> wrote in message
news:GVLvj.33185$dA2.10442@read2.cgocable.net
> Hey Bogus, here is a huge ethics win from Ireland.
>
> http://orato.com/node/12...
>
>
> Phil Scott
>
> Phil knows BB and the freezone are very much disconnected
> from the Church of Scientology. There is no logical
> reason for Phil to try and get his digs into BB by
> insulting his as Bogus (not authorised by the church) AND
> hit him with some bad pr piece for the church of
> scientology. Phil just hates any scientologists and
> anything scientological. He is a bigot, a hate monger, a
> merchant of chaos and wants us all gone.
> And like I have told you and others in the freezone BB,
> IF the church of scientology ever does fall, you can kiss
> your asses in the free goodbye too. There will be no
> toleration of anyone having workable technology anywhere,
> except some government black ops departments to make
> slaves of the world populations with.
> Scientology is best left in the hands of the public where
> it is now with the C of S training people into it who
> want to be trained. Even the freezone is still the
> practice of scientology on some level.
> But the Phil Scotts of this world would prohibit the
> practice of scientology anywhere by anyone if he has his
> way.
> Nelson

Your post has been saved for posterity, and I thank you for making it.

There is absolutely no one better at illustrating the utter insanity of
Scientology than a Scientologist


Nelson

2/23/2008 6:05:00 AM

0


"t_shuffle" <thorazineshuffle@gmail.com> wrote in message
news:lJMvj.3444$Mh2.2354@nlpi069.nbdc.sbc.com...
>
>
> "Nelson" <nhenderson3@cogeco.ca> wrote in message
> news:GVLvj.33185$dA2.10442@read2.cgocable.net
>> Hey Bogus, here is a huge ethics win from Ireland.
>>
>> http://orato.com/node/12...
>>
>>
>> Phil Scott
>>
>> Phil knows BB and the freezone are very much disconnected
>> from the Church of Scientology. There is no logical
>> reason for Phil to try and get his digs into BB by
>> insulting his as Bogus (not authorised by the church) AND
>> hit him with some bad pr piece for the church of
>> scientology. Phil just hates any scientologists and
>> anything scientological. He is a bigot, a hate monger, a
>> merchant of chaos and wants us all gone.
>> And like I have told you and others in the freezone BB,
>> IF the church of scientology ever does fall, you can kiss
>> your asses in the free goodbye too. There will be no
>> toleration of anyone having workable technology anywhere,
>> except some government black ops departments to make
>> slaves of the world populations with.
>> Scientology is best left in the hands of the public where
>> it is now with the C of S training people into it who
>> want to be trained. Even the freezone is still the
>> practice of scientology on some level.
>> But the Phil Scotts of this world would prohibit the
>> practice of scientology anywhere by anyone if he has his
>> way.
>> Nelson
>
> Your post has been saved for posterity, and I thank you for making it.
>
> There is absolutely no one better at illustrating the utter insanity of
> Scientology than a Scientologist
>

Trying to protect the credibility of your anti-cult-cult's leader?
You attack me and scientology instead of addressing the point I made.
Confront the issue I raised and comment on topic or STFU.

Nelson


t_shuffle

2/23/2008 7:10:00 AM

0



"Nelson" <nhenderson3@cogeco.ca> wrote in message
news:fIOvj.23897$612.2982@read1.cgocable.net

> Trying to protect the credibility of your
> anti-cult-cult's leader? You attack me and scientology
> instead of addressing the point I made. Confront the
> issue I raised and comment on topic or STFU.
> Nelson

Once again, I thank you. I couldn't make this stuff up if I tried.

anti-cult-cult's leader.


Nelson

2/23/2008 7:58:00 AM

0


"phil scott" <phil@philscott.net> wrote in message
news:a146616b-b6d4-4332-9693-89eba9138acf@p43g2000hsc.googlegroups.com...
On Feb 22, 6:54 pm, "Nelson" <nhenders...@cogeco.ca> wrote:
> "phil scott" <p...@philscott.net> wrote in message
>
> news:5311fc85-209a-4462-bcf2-265540765381@h25g2000hsf.googlegroups.com...
> On Feb 22, 5:58 pm, bb <basic2ba...@yahoo.com> wrote:
>
>
>
>
>
> > TECH outside COS: Could you believe Ethics tech wins?
>
> > --- franklin freeman <franklin008@ earthlink. net> wrote:
>
> > > "I identified the ways I have been holding myself back, participating
> > > and accepting this pattern
> > > of living... I experienced the positive effects of releasing this
> > > pattern, with the
> > > understanding of the TOOLS with which to transform my circumstances.
> > > Beautiful!" - CB
>
> > > ************ *****
>
> > > "The workshop present s a well organized approach to the subject of
> > > Integrity.
> > > I had several experiences of joy (release)......while participating in
> > > this workshop. The Self
> > > Empowerment Exercise was and is a source of some very powerful
> > > positive
> > > feelings about self. The
> > > Program is a valuable tool for any individual, facilitator or
> > > organizational consultant. It
> > > should assist anyone to improve his or her life..............
> > > I feel affirmed by the learning points that Mary has shared with us,
> > > and
> > > I feel I can apply
> > > them in my own life and help others to do the same". - NM
>
> > For more information on services in the Freezone,
> > mail me, Terril Park, at bbafzao@hotmail. com
> > This address can also be found in the next URL.
>
> > To find out more about us and to join our
> > forums see our websites at :-
>
> >http://www.freewebs.com/techouts...
>
> >http://internationalfr...
>
> > Below one may see a British TV program of
> > scientology as its use.
>
> >http://video.google.co.uk/videoplay?docid=1786568759674213741&a...
>
> > For those who are quite new to the subjects of
> > Dianetics and Scientology, we have a forum where
> > your questions can be answered, and their is a minimum
> > of the quite extensive specialised terminology of
> > these subjects. The forum website also has a couple of
> > dictionaries of scientology terms.
>
> >http://groups.yahoo.com/group/F...
>
> Hey Bogus, here is a huge ethics win from Ireland.
>
> http://orato.com/node/12...
>
> Phil Scott
>
> Phil knows BB and the freezone are very much disconnected from the Church
> of
> Scientology. There is no logical reason for Phil to try and get his digs
> into BB by insulting his as Bogus (not authorised by the church) AND hit
> him
> with some bad pr piece for the church of scientology. Phil just hates any
> scientologists and anything scientological. He is a bigot, a hate monger,
> a
> merchant of chaos and wants us all gone.
>
> And like I have told you and others in the freezone BB, IF the church of
> scientology ever does fall, you can kiss your asses in the free goodbye
> too.
> There will be no toleration of anyone having workable technology anywhere,
> except some government black ops departments to make slaves of the world
> populations with.
>
> Scientology is best left in the hands of the public where it is now with
> the
> C of S training people into it who want to be trained. Even the freezone
> is
> still the practice of scientology on some level.
>
> But the Phil Scotts of this world would prohibit the practice of
> scientology
> anywhere by anyone if he has his way.
>
> Nelson- Hide quoted text -
>
> - Show quoted text -



BB... thats bogus / bogus .....got the nick because he is such a
fraudulent pimp boy for elrongs crap....

then
he had some gains, and became a little less fraudulent, so I promoted
him to 'basially/bogu's..

progress in scientology is
slow but certain... I wish bogus the very beest in his endeavors.


Phil Scott
......................................................................

"such a faudulent pimp boy for elrongs crap....? elrongs crap Phil?
Your words betray your position that you are only against corruption etc.
The fact is you loath scientology and anything scientological. elrongs crap
eh? Well that is what we have as our religion Phil, so back off with your
anti religious slurs. You are not what you pretend to be. You are just what
you are, a total asshole with his own cult following. (spit)

Nelson



Jonathon Barbera

2/23/2008 1:03:00 PM

0

On Fri, 22 Feb 2008 21:54:28 -0500, "Nelson" <nhenderson3@cogeco.ca>
wrote:


>
>
>Phil Scott
>
>Phil knows BB and the freezone are very much disconnected from the Church of
>Scientology. There is no logical reason for Phil to try and get his digs
>into BB by insulting his as Bogus (not authorised by the church) AND hit him
>with some bad pr piece for the church of scientology. Phil just hates any
>scientologists and anything scientological. He is a bigot, a hate monger, a
>merchant of chaos and wants us all gone.
>
>And like I have told you and others in the freezone BB, IF the church of
>scientology ever does fall, you can kiss your asses in the free goodbye too.
>There will be no toleration of anyone having workable technology anywhere,
>except some government black ops departments to make slaves of the world
>populations with.
>
>Scientology is best left in the hands of the public where it is now with the
>C of S training people into it who want to be trained. Even the freezone is
>still the practice of scientology on some level.
>
>But the Phil Scotts of this world would prohibit the practice of scientology
>anywhere by anyone if he has his way.
>
>Nelson
>


First they came for the Church of the Scientology but I did nothing
because I was no longer in the Church of Scientology.

Next they came for Ron's Org and the Freezone but I did nothing
because I wasn't in their groups.

Then they came for the independent Scientologists and anyone else
using auditing or an e-meter.

Love,
-- Jonathon

Seebs

2/23/2008 5:49:00 PM

0

On 2008-02-23, intergalacticexpandingpanda@hotmail.com <intergalacticexpandingpanda@hotmail.com> wrote:
> I'm not a believer in the "Tech", but anyone want to experiment with
> it they have every right to do so. If history shows they got
> something, great.

Indeed, despite the consistent lies from the CoS, even Germany feels the same
way. There's no law, in Germany, against auditing or using an e-meter.

--
Copyright 2008, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net
http://www.seeb... <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/...(Scientology) <-- get educated!