functional-abstraction/functools

View on GitHub
src/rcurry.js

Summary

Maintainability
A
3 hrs
Test Coverage
import rbind from './rbind.js';

export default function rcurry(callable, arity) {
    return function () {
        const args = Array.prototype.slice.call(arguments, 0);

        const fn = rbind(callable, this, args);

        const i = arity - args.length;

        if (i <= 0) {
            return fn();
        }

        return rcurry(fn, i);
    };
}