3 ms·
Now replace |> with . And you have the previous code example. The difference is completely superficial.
by amw-zero 5y ago
Now replace |> with . And you have the previous code example. The difference is completely superficial.
- machiaweliczny 5y agoIt's not because you can use any function with pipeline and with dots chaining you can use only methods returned by previous function call.
- kazinator 5y agoThat is false; you cannot chain functions that do not return a value that is suitable as an argument to the next function. a.this().that() requires that a.this() returns an object on which .that() can be invoked. (that (this a)) requires that (this a) returns an object that is a suitable argument to that.
- jonnycat 5y agoThe end result is superficially different. That's the point - we like the flow of the end result! But the implementation is completely different, as it's pure functional compared to object oriented. "string".do_stuff() - do_stuff() is a method on the "string" class, with all of the potential gotchas that might come with an OO implementation. Does the method mutate the internal state of the object? Does the particular class override the default implementation? Is it a monkey-patched implementation (the issue raised by this article)? "string" |> do_stuff() - do_stuff() is a standalone pure function. The data is immutable and does exactly what it says.
- kazinator 5y agoNot completely, because the . has a meaning: select a member/field/slot from a class object.