With the help of Proxymise it even works with asynchronous functions.
There is also a proposal for a pipeline operator that will allow functional code to look more fluent without the need of this. g(f(x)) becomes x |> f |> g
x |> f |> g
That's awesome. I'll check out Proxymise. Looks like a neat wrapper for handling async code. As you said help's to remove a lot of the .then()'s
There is but one thing I HATE about fluent api - the code looks quite ugly. The indentation is screwed up if you chain more calls and it looks ridiculous if you have to nest a few levels... and it's quite easy to fall into that as well.
PS: Your equals should return the value instead of calling a callback. The code looks much more sane this way.
I agree about fluent api's becoming quickly hard to read and if you start nesting, then try something different.
BTW, the equals accepts either a call back or returns the result. I should check if there was a callback passed to it, though as a param.
Equal returns "this", not the result. The only other note I have about the example is that the internal property is called "start" instead of "result" (because this is what it is - it's the result, start is only the initial value).
Here is some food for thought:
Chaining has no performance benefit over calling the methods separately. Calling a callback to return the result however has a very dramatic performance impact.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.