3 ms·
The point is it looks a lot better than several nested function calls, especially when the order of the calls are important. In JS you can do stuff like this:
by scottmf 9y ago
The point is it looks a lot better than several nested function calls, especially when the order of the calls are important.
In JS you can do stuff like this:
const rules = parsedTags
.split(';')
.map(item => item.trim())
.filter(item => !!item);
But in some functional languages you would have to do something like this:
Array.filter(Array.map(String.split(parsedTags, ';'), item => String.trim(item)), item => !!item);
Which makes it a lot more difficult to write/understand. (Note the order in which the functions will be called).
With a pipe operator you can do something like this:
parsedTags
|> Array.split(';')
|> Array.map(item => String.trim(item))
|> Array.filter(item => !!item);
Now that people are writing more functional JS, a pipe operator becomes much more useful since you can't always chain function calls like the JS example above.