Giter VIP home page Giter VIP logo

Comments (12)

haltcase avatar haltcase commented on August 17, 2024 1

@chocolateboy added reference in the readme.

Thanks for all the well put together proposals in here by the way - really appreciate that!

edit: also if you'd like _ + _ supported you're welcome to open a new issue for that - I think I could be influenced I'm just not sold on its worth right now.

from babel-plugin-partial-application.

haltcase avatar haltcase commented on August 17, 2024 1

@chocolateboy published as v1.1.0

@xtuc the main problem I see is transform-scala-lambda does not support nested structures like _.foo.bar, _.foo().bar === true, etc.

from babel-plugin-partial-application.

chocolateboy avatar chocolateboy commented on August 17, 2024

Hmm, after playing with them both, it appears that the scope of the other module is much more limited i.e. unlike Scala, it can't handle:

Input

foo.map(_.bar.baz)

Output

babel-plugin-transform-scala-lambda

foo.map((_2 => {
    return _2.bar;
}).baz);

babel-plugin-partial-application 👍

foo.map(_a => {
    return _a.bar.baz;
});

from babel-plugin-partial-application.

chocolateboy avatar chocolateboy commented on August 17, 2024

But then it does support multiple arguments like Scala:

Input

foo.reduce(_ + _)

Output

babel-plugin-partial-application

foo.reduce(_ + _);

babel-plugin-transform-scala-lambda 👍

foo.reduce((_2, _3) => {
    return _2 + _3;
});

from babel-plugin-partial-application.

chocolateboy avatar chocolateboy commented on August 17, 2024

Incidentally, while this doesn't quite work yet (with transpiled template strings):

Input

foo.map(`[ ${_} ]`)

Output

babel-plugin-transform-scala-lambda

foo.map((_2 => {
    return "[ " + _2;
}) + " ]");

babel-plugin-partial-application

foo.map("[ " + _ + " ]");

- it would be great if it could, and if this could be extended to arbitrary expressions e.g.:

Input

foo.map([ _ + _ ])

Output

Either

foo.map(it => [ it + it ])

Or

foo.map((it, index) => [ it + index ])

Ideally with an option to choose between the different interpretations of multiple placeholders :-)

from babel-plugin-partial-application.

haltcase avatar haltcase commented on August 17, 2024

Funny! I wasn't aware of transform-scala-lambda! I had been searching for 'partial application' so that one never popped up. Looks like mine does have more features overall but like you mentioned doesn't support binary expressions like the other..

I'm just not sold on the binary expressions though like _ + _. I just don't think it's very useful. I'm open to examples of where it's actually an improvement over the regular JS lambda though but it just doesn't seem like enough. Maybe it's necessary to support template strings though.

from babel-plugin-partial-application.

xtuc avatar xtuc commented on August 17, 2024

Hi guys, i'm glad you mentioned my plugin 👍

I also planned to support this:

const mapToName = _.name

console.log(mapToName({name: 'Sven'});

Since we are both missing some features, what do you think publishing a package which inherits from both?

from babel-plugin-partial-application.

haltcase avatar haltcase commented on August 17, 2024

@chocolateboy turns out I influenced myself on this one. I thought of a few cases where binary expressions can be useful for placeholders and implemented it last night. Made the smart-ish move and waited until this morning to verify tests & push 😆

The cases that changed my mind were:

foo.filter(_ % 2 === 0)
foo.filter(_.level > 0)
foo.filter(_.indexOf('sweet') > -1)
foo.filter(_.getName().length > 10)

... all of which are supported now and will be published in 1.1.0 soon.

@xtuc yo! no problem - we've run into a bit of co-invention! Per the above I'm not sure how that changes things for you on a new package, but I'm always down for collaboration.

from babel-plugin-partial-application.

chocolateboy avatar chocolateboy commented on August 17, 2024

Awesome! Looking forward to trying it out 👍

from babel-plugin-partial-application.

xtuc avatar xtuc commented on August 17, 2024

Ok, you could include my plugin as dependency of yours. This would avoid some code duplications and could be simpler to maintain.

You can use the inherits feature in Babel's plugins or I will update my plugin to simplify integration.

What do you think?

from babel-plugin-partial-application.

xtuc avatar xtuc commented on August 17, 2024

Yes, does your plugin support it? This was just an idea but if you don't have an advantage we can leave it there.

I can actually work on my plugin to add the support of it.

from babel-plugin-partial-application.

haltcase avatar haltcase commented on August 17, 2024

Mine does, yeah, on member expressions and binaries within members and such.

heroes.filter(_.getPower().level > 9000)

becomes

heroes.filter(_a => {
  return _a.getPower().level > 9000;
})

from babel-plugin-partial-application.

Related Issues (7)

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.