Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zeusdeux/auto-curry
Supercharge your functions by giving them the ability to auto-curry
https://github.com/zeusdeux/auto-curry
Last synced: 16 days ago
JSON representation
Supercharge your functions by giving them the ability to auto-curry
- Host: GitHub
- URL: https://github.com/zeusdeux/auto-curry
- Owner: zeusdeux
- License: mit
- Created: 2014-09-01T07:08:00.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2021-10-22T06:40:15.000Z (about 3 years ago)
- Last Synced: 2024-10-16T19:25:09.783Z (27 days ago)
- Language: JavaScript
- Homepage: https://www.npmjs.org/package/auto-curry
- Size: 74.2 KB
- Stars: 7
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
auto-curry
==========Supercharge your functions by giving them the ability to auto-curry.
> Note:
> This library actually uses partial application internally and not currying. So, yes, the name is a misnomer.
> It is the result of my incorrect understanding of the concepts when I wrote the library.
> It is still perfectly usable and is used in production.# Installation
```javascript
npm install auto-curry --save
```# Usage
In `node`, you can just `require('auto-curry')`.
In the browser, you can use `build/auto-curry.min.js`
- with `require.js`, `browserify` etc
- directly by using `window.autoCurry`## Node
```javascript
var cu = require('auto-curry');
var add = cu(function (a, b) {
return a + b;
});
var messWithThis = cu(function(v){
this.a.push(v);
return ++v;
});
var map = cu(function map(fn, list) {
var self = arguments[2] ? arguments[2] : this;
try {
return list.map(fn, self);
}
catch (e) {
return [].map.call(list, fn, self);
}
});
var x = {a: []};console.log(map(add(1), [1, 2, 3])); //[2, 3, 4]
console.log(map(messWithThis, [1,2,3], x)); //[2, 3, 4]
console.log(x.a); //[1, 2, 3]
```## Browser
```javascript
var cu = window.autoCurry; //using it off the global
var add = cu(function (a, b) {
return a + b;
});
var messWithThis = cu(function(v){
this.a.push(v);
return ++v;
});
var map = cu(function map(fn, list) {
console.log(arguments[2]);
var self = arguments[2] ? arguments[2] : this;
try {
return list.map(fn, self);
}
catch (e) {
return [].map.call(list, fn, self);
}
});
var x = {a: []};console.log(map(add(1), [1, 2, 3])); //[2, 3, 4]
console.log(map(messWithThis, [1,2,3], x)); //[2, 3, 4]
console.log(x.a); //[1, 2, 3]
```# License
[MIT](https://github.com/zeusdeux/auto-curry/blob/master/LICENSE)
# Changelog
#### `0.2.1`
- Now, if the function passed to `auto-curry` has an arity of one, the function itself is returned. Earlier this was only for zero arity functions.