Coder Social home page Coder Social logo

Comments (7)

SuperPaintman avatar SuperPaintman commented on June 30, 2024

So, I don't fully understand what you mean.

Example in a proposal

from babel-plugin-transform-pipeline.

littledan avatar littledan commented on June 30, 2024

For example, if I have

let log = [];
function f() { log.push("f") }
function g() { log.push("g") }
f() |> g()

After that code runs, log should be ["f", "g"].

I don't see examples in the proposal, probably because it doesn't really make sense to write code this way.

from babel-plugin-transform-pipeline.

SuperPaintman avatar SuperPaintman commented on June 30, 2024

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?

from babel-plugin-transform-pipeline.

littledan avatar littledan commented on June 30, 2024

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 f() |> g() is related to the code g()(f()).

But! They differ in the evaluation order of f() vs g(). In the pipeline example, f() runs first. But in the normal function call code, g() goes first.

This can be fixed by desugaring into something like this:

let __arg = f();
let __fn = g();
__fn(__arg)

from babel-plugin-transform-pipeline.

SuperPaintman avatar SuperPaintman commented on June 30, 2024

Oh, I understood what you mean, but I didn't find an opinion on this case in proposal.
I think, you'd better ask this question in proposal repo: https://github.com/tc39/proposal-pipeline-operator
Please let me know later what they think about this.

Or my implementation is wrong?

from babel-plugin-transform-pipeline.

littledan avatar littledan commented on June 30, 2024

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.

from babel-plugin-transform-pipeline.

littledan avatar littledan commented on June 30, 2024

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.

from babel-plugin-transform-pipeline.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.