4 ms·
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.fluentcp
by 0xmarcin 4y ago
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-stream/ 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.