3 ms·
If we're going to do this operator, I would prefer a regular arrow: import { sortBy, filter, map } from 'array-like'; let names = document.querySelect
by wycats 11y ago
If we're going to do this operator, I would prefer a regular arrow:
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.
- wycats 11y agoThat said, the main counterargument to this proposal is that it's already possible to get "left to right" composition in userland without this operator, as underscore shows. 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.
- vruiz 11y ago> I personally find this more readable than ... the proposed pipeline operator, which doesn't have an immediate meaning to my eyes. Really? have you never seen unix pipes?
- wycats 11y agoI would find pipes to be very readable (but the single pipe operator is taken). The triangle isn't immediately an analogy to "unix pipes".
- tallerholler 11y agothat won't play nice with coffeescript!
- wycats 11y agoCoffeeScript should have thought of that ;)
- kenOfYugen 11y agoJS 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.
- tallerholler 11y ago+1
- danbruc 11y agoWhy the arrow? That works just fine with a dot. let names = document.querySelectorAll('.entry') .sortBy('title') .filter(entry => entry.getAttribute('data-url') in whitelist) .map(entry => entry.getAttribute('name');
- wycats 11y agoOnly if those methods are added to NodeList, which they haven't been. (and of course 'sortBy' is nonstandard)
- danbruc 11y agoOf course, but you can extend the underlying type. But I can see why you wouldn't want to do that over and over for all collection types. There is probably a tradeoff between reusing the established dot syntax and having a different syntax to be explicit about invoking a non-member function.
- pygy_ 11y ago> I would prefer a regular arrow 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#Anchor_11 https://msdn.microsoft.com/en-us/library/dd233229.aspx#Ancho... http://docs.julialang.org/en/release-0.4/stdlib/base/?highlight=|%3E#Base.|%3E http://docs.julialang.org/en/release-0.4/stdlib/base/?highli... http://livescript.net/#piping http://livescript.net/#piping
- wycats 11y agoFair enough. 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.
- msoad 11y agoan Array.from will make it possible to do it like regular arrays. I don't see a good use case for this operator really.