2 ms·
But what happens when there are more than two or three transformations? wrapTag("p", capitalize(parseTemplate(sanitize("hello, %s"), "Sam")))) This is a con
by sodapopcan 5y ago
But what happens when there are more than two or three transformations?
wrapTag("p", capitalize(parseTemplate(sanitize("hello, %s"), "Sam"))))
This is a contrived example in terms of the actual functions being called, but it's not out of the question to have at least this many transforms (just think of a method chain of more than two or three operations if you are coming from an OO point of view).
My main reason for replying to this thread is to counter this idea that pipes are inelegant—this simply isn't true. At the same time, I personally don't care if they make it into JS or not.
edited for clarity/grammar
- crooked-v 5y agoFor a direct comparison: wrapTag('p', capitalize(parseTemplate(sanitize('hello, %s'), 'Sam'))) 'hello, %s' |> sanitize |> parseTemplate(%, 'Sam') |> capitalize |> wrapTag('p', %) And with some little adjustments with currying even those % placeholders can go away.
- inbx0 5y agoNote that, in the current form of the JS proposal, you also need to use the placeholder in unary functions. I.e. sanitize(%) and capitalize(%)