by wycats · 10y ago · 0 comments
import { sortBy, filter, map } from 'array-like';
let names = document.querySelectorAll('.entry')
-> sortBy('title')
-> filter(entry => entry.getAttribute('data-url') in whitelist)
-> map(entry => entry.getAttribute('name');
I personally find this more readable than either the bind proposal (which looks too much like a property access, and not enough like a function call, to me) and the proposed pipeline operator, which doesn't have an immediate meaning to my eyes.And I want it painted green ;-)
> ... which doesn't have an immediate meaning to my eyes.
It's a matter of background. F#, Julia and Livescript have identical operators, likely among others.
https://msdn.microsoft.com/en-us/library/dd233229.aspx#Ancho...
http://docs.julialang.org/en/release-0.4/stdlib/base/?highli...
I personally consider compound operators (asymmetrical) to be pretty risky (the do, indeed, depend on background), and I like '->' because it has a clear meaning outside of programming.
But you're right, this is a bikeshed.
I'd prefer either version of the pipeline operator to bind.
The main counterargument to "do it like underscore" is that underscore still ends up being an object whose methods are added to a prototype, not imported.
The benefit of the "pipeline" or "bind" approach is that you get left-to-right composition while still importing the names you're using.
Really? have you never seen unix pipes?
let names = document.querySelectorAll('.entry')
.sortBy('title')
.filter(entry => entry.getAttribute('data-url') in whitelist)
.map(entry => entry.getAttribute('name');(and of course 'sortBy' is nonstandard)
var result = exclaim(capitalize(doubleSay("hello")));
ES7 Proposal: The Pipeline Operator var result = "hello"
|> doubleSay
|> capitalize
|> exclaim;
CoffeeScript result = exclaim capitalize doubleSay 'hello'
I'll take CoffeeScript.