Skip to content

Instantly share code, notes, and snippets.

@rauschma
Created November 11, 2017 05:14
Show Gist options
  • Save rauschma/985d6fda6227bed5599f5f67764d6933 to your computer and use it in GitHub Desktop.
Save rauschma/985d6fda6227bed5599f5f67764d6933 to your computer and use it in GitHub Desktop.
function curry2(func) {
return function (...args) {
if (args.length < 2) {
return func.bind(this, ...args);
}
return func.apply(this, args);
};
}
@aminpaks
Copy link

aminpaks commented Nov 11, 2017

assuming that func has exactly two parameters (= 3 type variables, incl. the result)

@rauschma That would make it much easier with the current implementation of Typescript:

function curry2<TF, TS, R>(func: (first: TF, second: TS) => R ): (first: TF, second: TS) => R {
    return function (first: TF, second: TS): R {
        return func.call(this, first, second);
    }
}

Example

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