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

1
2
3
4
5
6
7
8
9
10
11
12
13
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

1
2
3
4
5
6
7
8
// 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.

GIF FTW!

curry-this

Thanks to Christoph Hermann and tomekwi for making cury more fun!

Suggest a module

Comments