Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of pipe with existing ECMAScript features #277

Closed
sharshuv-quotient opened this issue Aug 25, 2022 · 2 comments
Closed

Implementation of pipe with existing ECMAScript features #277

sharshuv-quotient opened this issue Aug 25, 2022 · 2 comments
Labels
duplicate Duplicate of another bug

Comments

@sharshuv-quotient
Copy link

I'm not sure if it's obvious, but it's something worth mentioning. At least for the "unary function" syntax, it is already possible to implement a pipe using functional programming principles, with a syntax that has mostly the same level of readability. RxJS are already doing that.

Here's an example of such an implementation that is supposed to work with any data type: https://stackblitz.com/edit/typescript-6z61aw?file=index.ts

Usage example:
(I'm using lodash/fp for the example)

const value = pipe([1, 2, 3], [
    map((x) => [x, x * 2]),
    flatten,
    sortBy((x) => x)
  ]
);
console.log(value); // => [1, 2, 2, 3, 4, 6]

I can understand if the proposed syntax is easier to read, and also this option only solve the case for the "unary function" proposition, but it's still something that I think is worth mentioning when thinking of how to expand the language spec.

Anyway I would love to hear some thoughts.

@noppa
Copy link
Contributor

noppa commented Aug 25, 2022

That's been discussed here quite a few times: #131, #146, #154, #164, #245
The operator in it's current Hack-style form will be more readable (ok ok I know that's debatable), more easily optimized by the engines, more "debuggable" with e.g. a step-by-step debugger, and appliable to more existing JavaScript functions, since they don't need to be unary or curried.

@js-choi js-choi added the duplicate Duplicate of another bug label Aug 25, 2022
@js-choi
Copy link
Collaborator

js-choi commented Aug 25, 2022

Thanks for opening an issue; we appreciate your feedback.

In addition to the issues already mentioned in #277 (comment), this issue also seems to be a duplicate of the currently open #273. (We do still need to add this as an FAQ about this to the explainer.)

Also, a proposal for a Function.pipe function was formally made on 2022-07; it was called proposal-function-pipe-flow. It was rejected by the Committee at that time. Many Committee delegates think that Function.pipe is easily implemented in userland as a one-line function; that its problem is better solved by a Hack-like operator; and that it would encourage partial function application, which may encourage poorly optimizable code, by allocating numerous throwaway callbacks in hot paths. (See #221 regarding performance concerns by the engine implementers regarding partial function application.)

Thanks again for opening this issue; please feel free to leave comments on #273 and #221.

@js-choi js-choi closed this as not planned Won't fix, can't repro, duplicate, stale Aug 25, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate Duplicate of another bug
Projects
None yet
Development

No branches or pull requests

3 participants