tc39 / proposal-pipeline-operator

A proposal for adding a useful pipe operator to JavaScript.
http://tc39.github.io/proposal-pipeline-operator/
BSD 3-Clause "New" or "Revised" License
7.52k stars 108 forks source link

Consider operator-free composition? #118

Closed dfahlander closed 6 years ago

dfahlander commented 6 years ago

Would it be even thinkable to allow whitespace as operator for this?

let result = exclaim(capitalize(doubleSay("hello")));
result //=> "Hello, hello!"

let result = "hello" doubleSay capitalize exclaim;

result //=> "Hello, hello!"

If so, this would open up for clean style expressions in JS, like:

import {or, and, startsWith, includes, above} from './operators';

let a = "X", b = "Y", c = 2;

let expression = (a startsWith "X") or (b includes "Y") and (c above 1);
charmander commented 6 years ago

ASI means this would require parentheses to be split across multiple lines (confusing), and b includes "Y" wouldn’t work anyway.

gilbert commented 6 years ago

@dfahlander You're thinking of a concatenative programming language. Unthinkable for JavaScript, but a great area to explore for new languages.

littledan commented 6 years ago

It's been a useful extension point of JS to be able to add a meaning to two tokens next to each other, separated by a space. For example, it was possible to add async/await this way. This syntax would risk closing that path off.

igabesz commented 6 years ago

This way JS would be way more error prone. (Typo edited.) Now two consecutive variables or functions are simply syntactically erroneous. This way two consecutive variables would always be syntactically correct and it may be executable if the latter is a function. That would lead to bazillion of runtime errors which are now caught during development (by IDE highlighting), building/transpiling, or worst case during page load (or require in Node).

mAAdhaTTah commented 6 years ago

Given how JS has been designed up to this point, that sounds like a negative to me.

littledan commented 6 years ago

I don't think we'll adopt this alternative, for the reasons which were documented in this thread.

elycruz commented 6 years ago

@dfahlander Hhahaha what a clever fellow indeed (:-D) (Tried to sneak in Haskell syntax ay!? hahaha (thumbsup :-D). Would've been good (may still be possible in some way) though the scope to implement this would be massive (as noted in discussion (above) and for other reasons (existing mechanisms that handle the same functionality etc. (may make runtimes a bit slow due the amount of work needed to make the functionality co-exists with existing functionality, et. al.)).