Hacker News new | past | comments | ask | show | jobs | submit login

Seems to me that someone "stole" it from F#. F# probably also take this idea from some unknown (to me) language. Here a similar idea in C++ https://www.fluentcpp.com/2019/10/18/piping-to-and-from-a-st...

This is generally a weakness of text based programming languages, that you cannot easily express graph flows like:

    / B1 \
 A>-|    | -> C
    \ B2 /
|> operator only solves the problem for non-branched flows like A -> B -> C making them more readable by removing nested calls.

In theory you can create something similar using JS OOP by attaching e.g. map/use(func) methods to every prototype:

  function use(func) { func(this); return this; }
  function map(func) { return func(this); }
and then:

  (1).map(n => n+1)
    .use(console.log)
    .map(n => "n = " + n)
    .use(n => console.log("str = $n"));
Introducing a new operator instead of a library is a huge effort. I don't think this proposal will succeed, especially that current custom operator support in JS is nil.



Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: