Skip to content

Instantly share code, notes, and snippets.

@stoeffel
Last active August 29, 2015 14:26
Show Gist options
  • Select an option

  • Save stoeffel/a90fd0941a4924308e0e to your computer and use it in GitHub Desktop.

Select an option

Save stoeffel/a90fd0941a4924308e0e to your computer and use it in GitHub Desktop.
nmotw curry-this

Curry-this

Curry-this makes creating curryied function simple and expresive by invoking curry with the function bind syntax ::. Apart from the expresive way of creating a curried function, the main feature are placeholders. A placeholder (_) is a Symbol which allows to curry specific arguments of a function.

Install it: npm install --save curry-this

Basic usage

const {curry, _} = require('curry-this')();


// Got a simple function?

const plus = (
    (a, b, c) => a + b + c
)::curry();

plus(1, 2, 3);  //» 6
plus(1)(2, 3);  //» 6
plus(1, 2)(3);  //» 6
plus(1)(2)(3);  //» 6

Placeholders

// Got a monster function?

const {open} = require('fs');
const newScript = open::curry(_, 'w', 0755, _);

newScript('do-wonders.sh', (error, file) => {
  // The `file` is ready.
});

You can try this with babel-node. Make sure that you use the --stage=0 option.

@hemanth
Copy link
Copy Markdown

hemanth commented Aug 6, 2015

babel-node --stage=0 curry_this.js

(function (exports, require, module, __filename, __dirname) { import placehold
                                                              ^^^^^^
SyntaxError: Unexpected reserved word
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:413:25)
    at Module._extensions..js (module.js:448:10)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/Hemanth/.nvm/versions/io.js/v2.4.0/lib/node_modules/babel/node_modules/babel-core/lib/api/register/node.js:214:7)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/private/tmp/l:1:20)
    at Module._compile (module.js:430:26)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment