“Piping” Methods In Methods Chaining

Lately I implemented this behavior for yii: github.com/garex/yii-pipe-behavior

It’s main purpose is to allow methods chaining for methods, that are getters. Something in such style could be implemented in any other language/framework. It’s more like syntactic sugar for fanats of method chaining.

From readme:

So my questions are:


[*]Can it be really useful? I implemented this stuff in late night and still not sure.

[*]Could it be a "bicycle"? May be such stuff exists in another lang/framework?


@via stackoverflow.com/questions/20985281/piping-methods-in-methods-chaining

I think saving results in a variable and passing it to the other method is much cleaner, readable, better supported by IDE’s and just more sane.

If you really want to continue chaining I’d extend the class to be traversable and make the gimmeAll method save results in some static property. Yes, that would break the existing design and anything that uses gimmeAll.

class Something


	public function gimmeAllToSomething()


        	return $this->toSomething($this->gimmeAll());



$bla = Something::create()->one()->two()->tree()->gimmeAllToSomething();

Yes, it’s a bit more code to type and test, but best programming practices aren’t about typing less.

Not more, I also like this. It was my 1st option before I start think about this exotic pipe stuff.

Why I write it?

In my case I have transform behavior, that have toSomething and theoretically more than 5 toBlaBla methods.

Also we have in each standard model at least 8 findBla methods. Then for this logic we should have about 40 methods in this behavior, that will do this? It was my main reason, when I thought about this exotic.

But from another point of view — all these risks are theoretical fears. Currently in real scenario I also used gimmeAllToSomething() approach.

Anyway thanks to all, who responded to poll/answered here :)

Check out this thread: http://www.yiiframework.com/forum/index.php/topic/50523-yii-active-collection-decorator/