Coder Social home page Coder Social logo

danieluhl / auto-curry Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zeusdeux/auto-curry

0.0 2.0 0.0 42 KB

Supercharge your functions by giving them the ability to auto-curry

Home Page: https://www.npmjs.org/package/auto-curry

License: MIT License

Makefile 8.68% JavaScript 91.32%

auto-curry's Introduction

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

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

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

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

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.

auto-curry's People

Contributors

danieluhl avatar zeusdeux avatar

Watchers

 avatar  avatar

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.