3 ms·
Maybe it's just me, but I don't see the purpose of a pipeline operator - at least in JS. From a cognitive perspective, it doesn't make code more readable or ea
by dvdhnt 7y ago
Maybe it's just me, but I don't see the purpose of a pipeline operator - at least in JS.
From a cognitive perspective, it doesn't make code more readable or easier to understand.
From a practical perspective, why? What can't we do with it that isn't aesthetic?
Edit: Okay, after reading through the article again, I get it. I've had issues with eager loading in Node AND I will say the pipeline is easier to understand than simply using generators. Good article.
- crooked-v 7y agoA simple example would be mixing map/reduce stuff on arrays with other non-built-in utility functions that take arrays without having to break the logical flow. For a very simple example, manipulating and summing an array of values: import { range, sum } from 'ramda'; range(0, 6) |> x => x.map(i => i * i) |> sum Compare to: import { range, sum } from 'ramda'; sum( range(0, 6) .map(i => i * i) ) ...and then add three or four other non-builtin methods in between map steps and consider the resulting readability.
- MFogleman 7y agoI mean, I think one of the big arguments against a pipeline operator is that you can easily roll your own with const pipe = (...fxs) => x => fxs.reduce((v, f) => f(v), x); If you're going to pull in ramda for example, they have their own pipe, and a map function that takes (predicate, array) as curried arguments, to aid with composition import { map, pipe, range, sum } from 'ramda'; pipe( range, map(i => i * i), sum )(0, 6) I haven't messed with HN formatting before, so I hope that turns out right. My team uses Ramda and pipes regularly in our Node code, and its absolutely wonderful