3 ms·
Ah, missed that example. I am not seeing a single good argument > Indeed, the benefits of method chaining are so attractive that some popular libraries contort
by zodiakzz 5y ago
Ah, missed that example. I am not seeing a single good argument
> Indeed, the benefits of method chaining are so attractive that some popular libraries contort their code structure specifically to allow more method chaining. The most prominent example is jQuery, which still remains the most popular JS library in the world. jQuery’s core design is a single über-object with dozens of methods on it, all of which return the same object type so that we can continue chaining. There is even a name for this style of programming: fluent interfaces.
Do they know what's so attractive about method chaining/fluent interfaces? They guarantee returning the same damn object/interface (tho the underlying values mutate). This pipe thing is complete opposite of that, what's the relevance here?
- danielsju6 5y agoIt's about reading the code in a natural order. jquery style: a().b().c().d() However this isn't tree shakable. modern esm: d(c(b(a()))) this proposal: a() |> b(%) |> c(%) |> d(%)
- lifthrasiir 5y agoI think this is a good summary of why pipeline operators are long sought, more so than the proposal. If you are not fundamentally against chaining calls, there is no fundamental reason to be against pipeline operators because it can be thought as a generalization of chaining with similar pros and cons.