News for hackers. Stuff that matters.
Re:A pipe operator for JavaScript: introduction and use cases by tzs on Saturday January 29, 2022 @09:01AM (#30126339)
Here are the two forms being offered for a pipe operator:

  const y = h(g(f(x))); // no pipe
  const y = x |> f(%) |> g(%) |> h(%); // Hack pipe
  const y = x |> f |> g |> h; // F# pipe
Why not use concatenation?

  const y = x f g h;
Re:A pipe operator for JavaScript: introduction and use cases by johannes1234321 on Saturday January 29, 2022 @10:06AM (#30126834)
> Why not use concatenation? > > const y = x f g h;

This can't be broken into multiple lines.

   const y = x f
   g h
Will have an implicit ; in between.

   const y = x 
          |> f
          |> g
          |> h; 
Will work as expected, and potentially increase readability.
Re:A pipe operator for JavaScript: introduction and use cases by zeroimpl on Saturday January 29, 2022 @10:33AM (#30127097)
Because then a missing comma somewhere becomes a weird bug, as opposed to a syntax error.

Languages with implicit string concatenation using no operator have found it to be a common source of bugs, eg python. See https://news.ycombinator.com/item?id=29841560

Re:A pipe operator for JavaScript: introduction and use cases by angus_gh on Saturday January 29, 2022 @01:40PM (#30129031)
Does your suggestion allow passing an extra argument into any of those functions? Like the

    value |> someFunction(1, %, 3)
Re:A pipe operator for JavaScript: introduction and use cases by bryanrasmussen on Saturday January 29, 2022 @09:40AM (#30126612)
In that case why not write

h g f x

and keep the ordering of functions the same between the different syntactical structures.