Earlier quoted context omitted.
And a lot more like JS than the F# proposal.
How so? JS already has operators, but placeholders is a totally new concept
Pipe Operator (|>) For JavaScript
381–390 of 437 posts
Re: Pipe Operator (|>) For JavaScript
#382Can't wait for this. Pipes are awesome in Elixir and bringing them to JS/TS will be great. To me this is both concise and readable: const weather = `https://api.weather.gov/gridpoints/TOP/31,80/forecast` |> await fetch(%) |> await %.json() |> %.properties.periods[0]
That is concise, readable, and does not have any room at all for error handling. If this was Rust, it could at least be turned into something which returned the right Err for what was happening. Without something like that, trying to add error handling to the things which may blow up would instantly turn it into gibberish. Every single function here can fail (the HTTP request could fail, the data returned could be un…
Re: Pipe Operator (|>) For JavaScript
#383I * HATE* pipes. For example from Elixir School ( https://elixirschool.com/en/lessons/basics/pipe_operator ): ``` foo(bar(baz(new_function(other_function())))) ``` They offer this example of an improvement: ``` other_function() |> new_function() |> baz() |> bar() |> foo() ``` While yes, pipes improve readability, how do they deal with errors? How do they deal with understanding what each thing is supposed to return?…
That's a limit of exception handling in Elixir. A good language treats errors as a first class type. Functions that can error have no business returning an A. Example given, the fetch API, is basically typed as fetch (): Promise In reality, there might not be A at all, it should return a data type such as Either (or Result) which encodes linearly and forces the consumer to consider and handle the error.
I already use Maybe patterns quiet a bit in my TS project but there always the libraries and frameworks you work with that don't. So yeah I can see it being a language level thing (the way Promises were used) pushing for wide adoption.
Re: Pipe Operator (|>) For JavaScript
#384Is this: Object.keys(envars) .map(envar => `${envar}=${envars[envar]}`) .join(' ') |> `$ ${%}` |> chalk.dim(%, 'node', args.join(' ')) |> console.log(%); Really better than: console.log(chalk.dim( `$ ${Object.keys(envars) .map(envar => `${envar}=${envars[envar]}`) .join(' ') }`, 'node', args.join(' ') )); That's the real-world example they have (I reformatted the second one slightly, because it looks better to me). N…
TC39 proposals often have rubbish real world examples that should never see the light of day in a JS codebase. It makes me really question the judgement of the people that are working on this language, and it explains how some of the shittier proposals manage to slip in and why the good ones are misused all over the place in every real world codebase when this is the kind of guidance devs have on where to use fancy n…
If the motivation behind these features are React components, javascript clearly lacks proper logic in array (and object) literals, like
'[' if (cond) […]expr1 [else […]expr2] ']'
Although it seems pretty strange to add syntax only because some specific user interface library together with a specific language extension could benefit from it.Re: Pipe Operator (|>) For JavaScript
#385Earlier quoted context omitted.
The Hack proposal is horrible imo because it doesn’t look like JS anymore. The F# proposal is 99% of the benefit whilst being actually approachable.
It absolutely is, but time and time again TC39 has followed few champions over the waves of people favoring F# pipes. It's incredible to me TC39 would rather have this monstruosity over F# pipes which are actually pretty similar to how most pipes work and read in most functional languages including unix `|` one.
Re: Pipe Operator (|>) For JavaScript
#386Earlier quoted context omitted.
Wouldn't it be better to use '->' as the operator? This is about dataflow so an arrow would represent that nicely. Whereas '|>' doesn't really "mean" anything. An arrow means that something flows in the direction of the arrow.
Sure, but I'd rather reserve that for a pattern-matching switch statement.
Re: Pipe Operator (|>) For JavaScript
#387I * HATE* pipes. For example from Elixir School ( https://elixirschool.com/en/lessons/basics/pipe_operator ): ``` foo(bar(baz(new_function(other_function())))) ``` They offer this example of an improvement: ``` other_function() |> new_function() |> baz() |> bar() |> foo() ``` While yes, pipes improve readability, how do they deal with errors? How do they deal with understanding what each thing is supposed to return?…
That's a limit of exception handling in Elixir. A good language treats errors as a first class type. Functions that can error have no business returning an A. Example given, the fetch API, is basically typed as fetch (): Promise In reality, there might not be A at all, it should return a data type such as Either (or Result) which encodes linearly and forces the consumer to consider and handle the error.
Re: Pipe Operator (|>) For JavaScript
#388 const thrush = (value, func, ...funcs) =>
func ? thrush(func(value), ...funcs) : value;
// no new syntax required
thrush(
envars,
Object.entries,
x => x.map(([key, val]) => `${key}=${val}`),
x => x.join(' '),
x => chalk.dim('$ ' + x, 'node', args.join(' ')),
console.log);
[1]: http://www.davidgoffredo.com/thrush.htmlRe: Pipe Operator (|>) For JavaScript
#389Earlier quoted context omitted.
The Hack proposal is horrible imo because it doesn’t look like JS anymore. The F# proposal is 99% of the benefit whilst being actually approachable.
Before ES6: “The arrow function proposal is horrible imo because it doesn’t look like JS anymore.”
Re: Pipe Operator (|>) For JavaScript
#390I hope Records & Tuples[0] land before this does. It would have meaningful and far reaching positive effects for the language, without much controversy. Like most of these things, it takes about 5-7 years for it to permeate through enough of the engines to be meaningfully useful in the day to day of web developers (node / deno typically 12-18 months tops). It would drastically speed up existing code once wide adoptio…
The one I really want is “do expressions”. I also can’t understand why anyone wants private fields over these kind of improvements. Lack of private fields in JS has literally never caused a big for me in 15 years of JavaScript development, but I have to use mutable variables and ugly if-else chains to 3 case assignment all the time!
Personally, for the 3-case assignment I would love to see one of the smarter pattern matching "match" expression proposals make it further along over the over-generalized "do expressions". Especially now that C# has pattern matching switch expressions.