What's so painful about just doing `exclaim(capitalize(doubleSay("hello")));`? Why introduce needless syntactic sugar that'll only confuse people about how UNIX pipes work?
ES7 Proposal: The Pipeline Operator
11–20 of 78 posts
Re: ES7 Proposal: The Pipeline Operator
#12Can we have this in C# 7? :)
Re: ES7 Proposal: The Pipeline Operator
#13Please no. Javascript's beauty lies in its versatile simplicity. Can we just leave these sorts of things to systems programming languages like C++? I came to javascript because of its lack of cruft, but if libraries start adopting this then I'll be forced to put it in my code as well. If that happens then I'll probably leave for nim or clojure, though that's not preferable.
Example:
(defn do-stuff [params-map]
(->
(build-object params-map)
(do-thing-with-object)
(extract-thing)
(format-thing)))
I'm not sure why you'd choose Clojure to get away from things like |>.Re: ES7 Proposal: The Pipeline Operator
#14I feel like that just confuses things for no good reason. It's no fewer characters than parens but provides as I see it less clarity.
Re: ES7 Proposal: The Pipeline Operator
#15 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.Re: ES7 Proposal: The Pipeline Operator
#16What's so painful about just doing `exclaim(capitalize(doubleSay("hello")));`? Why introduce needless syntactic sugar that'll only confuse people about how UNIX pipes work?
(because (there (is (such (a (thing (as (too (many parens)))))))))
Nested function do one thing on a chunk of data, then another, then another.
*nix pipelines apply all the filters at once and control the scheduling and lifetime of the filters.
Those are quite different concepts, and I think it's confusing to conflate the two. Plus every decent editor can handle paired parentheses.
Re: ES7 Proposal: The Pipeline Operator
#17I like this a lot. It's similar to the proposed function bind syntax[1], but a bit more friendly to not-`this`-related use: function bindMap(fn) { return this.map(fn) } [ 1, 2, 3 ]::bindMap(n => n + 1) // standalone use: bindMap.call(arr, fn) function pipelineMap(fn) { return arr => arr.map(fn) } [ 1, 2, 3 ] |> pipelineMap(n => n + 1) // standalone use: pipelineMap(fn)(arr) (Also nice that it works in a very similar…
The main goal of all of these proposals is "left to right" composition when working with functions, and functions take parameters.
Re: ES7 Proposal: The Pipeline Operator
#18Please no. Javascript's beauty lies in its versatile simplicity. Can we just leave these sorts of things to systems programming languages like C++? I came to javascript because of its lack of cruft, but if libraries start adopting this then I'll be forced to put it in my code as well. If that happens then I'll probably leave for nim or clojure, though that's not preferable.
Re: ES7 Proposal: The Pipeline Operator
#19What's so painful about just doing `exclaim(capitalize(doubleSay("hello")));`? Why introduce needless syntactic sugar that'll only confuse people about how UNIX pipes work?
(because (there (is (such (a (thing (as (too (many parens)))))))))
Re: ES7 Proposal: The Pipeline Operator
#20If 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…
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.