-
Notifications
You must be signed in to change notification settings - Fork 5
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
Evaluate left argument before right #2
Comments
So, I don't fully understand what you mean. |
For example, if I have let log = [];
function f() { log.push("f") }
function g() { log.push("g") }
f() |> g() After that code runs, I don't see examples in the proposal, probably because it doesn't really make sense to write code this way. |
Yeah, that's right. These ways are equivalent: Calling in calling: let log = [];
function f() { log.push("f") }
function g() { log.push("g") }
f() |> g
console.log(log) // => ["f", "g"] Pipeline: let log = [];
function f() { log.push("f") }
function g() { log.push("g") }
g(f())
console.log(log) // => ["f", "g"] And, as I understand it, when we use a pipeline, we say: f() // Get result of this function
|> // and put it as a first parameter in to
g // that function, and call it. Or did I misunderstand you? |
Sorry, there was a typo in my example, and it seems like you fixed it in a direction that's different from what I was going for. It should be: function g() { log.push("g"); return () => {} } Then, the code But! They differ in the evaluation order of This can be fixed by desugaring into something like this: let __arg = f();
let __fn = g();
__fn(__arg) |
Oh, I understood what you mean, but I didn't find an opinion on this case in proposal. Or my implementation is wrong? |
Well, that proposal doesn't have specific enough spec text to say things one way or another. I'd be really surprised if it went any other way than left-to-right (and I think it would be shot down in committee if so), but it would be fine with me if you feel like waiting for more solid confirmation first. |
I made a spec text proposal at tc39/proposal-pipeline-operator#51 which evaluates the left argument before the right one. I'd be interested in any feedback you have. |
Looking at the source of this module, it seems to transform
x |> f
directly intof(x)
. However, any standardized proposal will likely evaluatex
first, beforef
.The text was updated successfully, but these errors were encountered: