-
Notifications
You must be signed in to change notification settings - Fork 107
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
Define an operator for tuples (n-arity) pipeline #178
Comments
On second thought we don't need this very much, since we have tuple destructuring. |
In the first step of the pipeline, IMHO given that even the minimal version of this proposal has been in a stalemate for years, the bar should be pretty high for adding new variants/features to it. |
I think this falls into a category of discussion that I have noticed a lot of, which is to try and get the pipe to be a swiss army knife. In most cases, the "problems" I see trying to be solved are easily addressed by wrapping in an anonymous function. |
As this proposal addresses a scalar (1-argument) pipeline, can we also have an operator to for an n-argument pipeline?
For example, call the operator
|>>
. Then we can writewhich is equivalent to
It seems like it should be possible to avoid defining operators for each arity as in F# ( |>, ||>, |||>, <|, <||, <||| ), but maybe someone can explain if this is not the case. Regarding TypeScript, as long as the functions in the pipeline return a tuple type instead of an array type, TypeScript can type-check the arity of each step without using an arity-specific operator. (This does not say that all steps must have the same arity.)
One question (which also applies to the proposed
|>
) is how arity mismatch should be handled. For example, when providing fewer arguments than the function's arity:Should this
[1, 2, undefined]
;(a, b) => (c) => a*a + b*b === c*c
; or(1) is consistent with the existing argument spread syntax. Similarly, argument spread syntax handles too may arguments by ignoring the extra args.
If accepted, other variants that apply to scalar pipeline
|>
would equally apply to tuple pipeline|>>
, such as optional chaining.The text was updated successfully, but these errors were encountered: