-
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
Should it be pipeline-expression with more operators [ "|>" | ":|>" | "?|>" | "?:|>" ] #210
Comments
More than one pipeline operator seems like it'd be very confusing. |
Some kind of short-circuiting operator is surely necessary at least. Otherwise aren't be back to the pre-optional-chaining bad old days, having to bog everything down with null/undefined checks, or otherwise end up with unsafe code? And If there isn't going to be additional operators, why have an operator at all? Wouldn't it be less syntactically noisy to use some kind of pipe statement, where do.pipe {
f();
^ + 1;
console.log(^);
} |
#159 already covers the possibility of an optional-pipe operator; let's leave discussion of that to that issue. So that leaves this issue to talk about a bind-pipe operator. I lean against it, for two reasons.
I'd be comfortable exploring this idea in the bind-operator repo as an option for spelling this particular binding use-case, but I don't want to push that proposal towards a particular solution ahead of time. No reason to have to decide this quickly; we can let pipeline mature in its own form and let binding decide to lean on this syntax or not in its own time. |
(For what it’s worth, I am exploring presenting a resurrected bind-operator proposal to TC39 at the next plenary meeting. I’ve been discussing with @hax on how it would work with his Extensions proposal. It’s in flux.) |
enum PipelineOperator {
"|>"
} |
I apologize, but I don't understand what any of that comment is about. |
simply what is the effect of x |> y
........
|> if (^ == undefined) break; else return ^;
.......
in case of not allow ==> we can ignore this issue in case of it is a good thing and we can plane to have it the current proposal AST i assume it can be represented as interface PipelineOperator <: Expression {
type: "PipelineOperator";
left: Expression;
right: Expression; // <<=== the pipe body
} or in the best case interface PipelineExpression <: Expression {
type: "PipelineExpression";
operator: "|>";
left: Expression;
right: Expression; // <<=== the pipe body
} examplex |> y
|> map
|> filter
|> breakExecutionOnCondition // if (^ == undefined) break; else return ^;
|> collect
{
type: "PipelineOperator",
left: {
type: "PipelineOperator",
left: {
type: "PipelineOperator",
left: {
type: "PipelineOperator",
left: {
type: "PipelineOperator",
left: x,
right: y
},
right: map
},
right: filter
},
right: breakExecutionOnCondition
},
right: collect
}
{
type: "PipelineExpression";
argument: x;
pipes: [
{
operator: '|>',
body: map
},
{
operator: '|>',
body: filter
},
{
operator: '|>',
body: breakExecutionOnCondition
},
{
operator: '|>',
body: collect
}
]
} the break point:
|
@salemebo i'm also not sure what you're talking about; JS doesn't have an AST in the spec. |
@ljharb yes, that is the point, can we have a Pipeline Expression that can be considered as |
ok so you're asking for |
the last value of placeholder |
then this proposal would have to answer all the same questions Why is, say, this: a |> b(^) |> ^ ? break : c() better than: a |> b(^) |> ^ ? do { break } : c() which would not require any special-casing of the break statement or pipeline? |
because the current proposal can't handle a so in future if |
I'm not sure why you think it couldn't. Function calls can't "handle a |
in this scenario, the
so, if we can x |> y
|> z
|> typeof ^ == 'string' ? do {break} : ^
|> map <<== how function `map` will handle a break, or the pipeline that contain `map` as body handle `break` statement
|> a
|> b
|> c |
@salemebo it would break out of the loop, and the pipeline would never resolve to any value at all. In your case, the last 4 pipeline pieces would never execute. |
I don't think the do proposal will help about the optional chaining.
So you would at least write it like {
const a =
x
|> y(^)
|> y(^)
|> do { break }
} But it still won't work....
And even it is in the same scope.
So a working one will looks like... let a = null
{
a = x
|> y(^)
|> y(^)
|> do { break }
} that looks a bit insane in my opinion. |
@mmis1000 pretty sure you can’t break out of a block like that anyways. |
Yes, my apologies—I am quite confused by this issue in general and by some of the comments. What does Are we talking merely about short-circuiting a chain of pipes, like with optional chaining |
yes, it must be labeled, so the code will be actually even longer. fail: {
break fail;
console.log('you never see me')
} This already works today, but I doubt do anyone actually write like this? |
BLOCK: {
a = x
|> y(^)
|> y(^)
|> do { break BLOCK };
} Note that this code will not compile. The last pipe expression is missing a topic. There must be a topic in every pipe step. You would want something like: BLOCK: {
a = x
|> y(^)
|> y(^)
|> do { if (something) break BLOCK; else ^; };
} But…I think this probably is off-topic from this issue. (Though I’m not really sure what the topic of this issue was in the first place…) If you have any more questions about how |
Yes, I think this issue can be closed now. The subtopic about an optional-chaining pipe is already being discussed in #198; the subtopic about a If there are any details in this thread that anyone still feels need to be addressed, please open a fresh issue focused on each. |
can we imagine that the ast of the new pipeline
expression
will be asthis will give us the control to
:|>
Bind PipelineFunctionExpression
to the return value^
(applied also on the first argument)
and execute the body.?|>
Optional chaining Pipeline^
is un defined or null, will stop execution the rest of PipeClauseotherwise will continue the execution.
?:|>
Optional chaining Bind Pipeline^
if not nullish, bind it asthis
to theFunctionExpression
.** and could add more operators if needed.
The text was updated successfully, but these errors were encountered: