haltcase / babel-plugin-partial-application Goto Github PK
View Code? Open in Web Editor NEW[DEPRECATED] Please use https://github.com/citycide/param.macro
Home Page: https://git.io/try-param.macro
License: MIT License
[DEPRECATED] Please use https://github.com/citycide/param.macro
Home Page: https://git.io/try-param.macro
License: MIT License
It uses it
as the default function parameter, like Groovy, but doesn't use _
to create partially-applied functions.
(As of 1.1, it uses underscores for unused parameters (which can be repeated, as in Go and Ruby).)
Surprised to not see this mentioned in the Comparison or See Also section (and vice versa (cc @xtuc)). It looks similar (but less flexible): babel-plugin-transform-scala-lambda.
It will be nice to have ability to use an argument few times in function body.
For example, we want to create isNaN function, which looks like this in classic JavaScript:
const isNaN = x => x !== x
So we want to write something like this:
const isNaN = _ !== _
But it will be compiled into
const isNaN = (_a, _b) => {
return _a !== _b
}
Not into
const isNaN = _a => {
return _a !== _a
}
This ability requires new syntax. For example Clojure anonymous function syntax:
(def isNaN #(= % %))
Or:
(def isNaN #(= %1 %1))
In this Clojure examples we use % for 1-arity functions, and %1, %2, ..., %n for n-arity functions.
Rewritten with this syntax example:
const isNaN = % !== %
And cases when we need more than one argument:
const array = [1, 2, 3, 4, 5]
array.reduce(%1 + %2)
// -> 15
Of course not necessary use % as placeholder, I use it just to keep a parallel with Clojure.
I've decided to deprecate this package in favor of my newer project param.macro
. It's more focused, explicit, and stable, though it does intentionally lack a few of the features from this plugin to achieve those things. It has the same online playground as this plugin so you can compare it immediately in your browser.
The main difference is that the feature set has been split into two symbols instead of one, _
and it
. This is phenomenally easier to handle (param.macro
uses far less code than this plugin) and also easier to understand. There are clear semantic differences between the two. From param.macro
's readme:
_
will always traverse upward out of the nearest function call, whileit
will be transformed in place.
it
will always refer to the first argument even when used multiple times in an argument list. Each_
will always refer to the next argument.
it
symbol )_
)param.macro
:In the interest of readable, easily understandable code these features are intentionally left out.
import
param.macro
:If anyone has questions on the differences or how to migrate let me know, but the readme and the playground should help a lot with that.
If you're interested in taking over the GitHub repo and the npm package, hit me up.
(_)(1,2,3)
and _(1,2,3)
get converted into _(1, 2, 3);
gets compiled to
(_pos) => {
return _pos + 0;
})(1, 2, 3));
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.